unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dave Goel <deego3@gmail.com>
To: 66940@debbugs.gnu.org, deego3@gmail.com
Subject: bug#66940: Dynamic scoping is all weird now?
Date: Sun, 5 Nov 2023 00:09:36 -0400	[thread overview]
Message-ID: <CAOCW0Dh6rWtkO-TDmEoSfKP0bNAMb_w1N+FxrA-NsEeP3MYDWg@mail.gmail.com> (raw)
In-Reply-To: <CAOCW0DjzvUWDO4NhtUiPjahAh7Jwn_T=up=26Gu+KQmMubzF7Q@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1847 bytes --]

I apologize.I meant to say it should print 0 to 10 the first time around
because ,ii should hardcode the value at the time of macro definition.
But, the second and third time are so absolutely weird?



On Sun, Nov 5, 2023 at 12:06 AM Dave Goel <deego3@gmail.com> wrote:

> I was playing around, checking my sanity re : dynamic scoping.  I'm
> probably rusty, but I could swear that on older emacsen, this sort of code
> would print 33 ten times.
>
>
> On emacs -Q with debian stable (28.2).
> I try this
>
>
> (progn
>   (setq lexical-binding nil)
>
>   (dotimes (ii 10)
>     (defmacro mac ()
>       `(message "%S" ,ii)
>       (sit-for 0.1))
>     (let ((old_ii ii))
>       (setq ii 33)
>       (mac)
>       (setq ii old_ii)
>       )))
>
> Exits without error the first two times, although, strangely, i don't see
> any messages the second time. (I expected to see ten 33's).
>
>
> *(a) As in, the second time, it doesn't print 33 ten times, as we would
> expect.*
> *(b) The third time is stranger. *
> Let's evaluate it a third time! The third time is even weirder.
> The third time, it complains
> Debugger entered--Lisp error: (void-variable ii)
>   (list 'message "%S" ii)
>   (lambda nil (list 'message "%S" ii) (list 'print ii) (sit-for 0.1))()
>   macroexpand((mac) nil)
>   macroexp-macroexpand((mac) nil)
>   macroexp--expand-all((mac))
>   macroexp--all-forms(((setq ii 33) (mac) (setq ii old_ii)))
>   macroexp--expand-all((let ((old_ii ii)) (setq ii 33) (mac) (setq ii
> old_ii)))
>
> and so on.
>
>
> The bug(?) was reproduced on 29.1 as well - by e1f on #emacs
>
> *(c) It gets even funnier. e1f changed ii to var, but the third time, it
> still complained about ii, with the above error message, and not about var.*
> I reproduced that as well.
>
> Dave
>
>
>

[-- Attachment #2: Type: text/html, Size: 3782 bytes --]

  reply	other threads:[~2023-11-05  4:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-05  4:06 bug#66940: Dynamic scoping is all weird now? Dave Goel
2023-11-05  4:09 ` Dave Goel [this message]
2023-11-05  6:04   ` Gerd Möllmann
2023-11-05  6:58     ` Dave Goel
2023-11-05  7:25       ` Gerd Möllmann
2023-11-05  8:12         ` Dave Goel
2023-11-05  8:39           ` Gerd Möllmann
2023-11-05 19:07             ` Dave Goel
2023-11-05 20:21               ` Dave Goel
2023-11-06  1:52               ` Michael Heerdegen
2023-11-06  6:25                 ` Gerd Möllmann
2023-11-06 16:49                   ` Drew Adams
2023-11-06  6:57                 ` Dave Goel
2023-11-07  5:59                   ` Michael Heerdegen
2023-11-08  2:49                     ` Dave Goel
2023-11-08  3:08                       ` Michael Heerdegen
2023-11-08  3:21                         ` Dave Goel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOCW0Dh6rWtkO-TDmEoSfKP0bNAMb_w1N+FxrA-NsEeP3MYDWg@mail.gmail.com \
    --to=deego3@gmail.com \
    --cc=66940@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).