Subject: bug#66940: Dynamic scoping is all weird now?

From: Dave Goel <[email-masked]>
Date: Sun, 5 Nov 2023 15:21:25 -0500

Here's the simplest MRE I have so far -

(progn
  (setq lexical-binding nil)

  (let ((ii 1))
    (defmacro mac ()
      `(message "%S" ,ii)
      )
    (mac)))

Eval it three times, using C-x C-e.
Error on the third time.

(Following the prior response, I figured I will discuss on devel first to
confirm before officially reporting it, but was kinda directed back here.)

On Sun, Nov 5, 2023 at 2:07 PM Dave Goel <[email-masked]> wrote:

> Gerd,
>
> Ok.
>
> I hope this bugreport is clearer -
>
> Here's some code.
>
> The variable ii is clearly set every time mac was defined OR called.
>
> backquote should expand, and mac should have read its content as (list
> 'message "%S" ii).
>
>
>
>
> (progn
>   (setq lexical-binding nil)
>
>   (dotimes (ii 10)
>     (defmacro mac ()
>       `(message "%S" ,ii)
>       )
>     (let
>         ((old_ii ii))
>       (setq ii 33)
>       (mac)
>       (setq ii old_ii)
>       )))
>
>
> You eval this code once. It works.
> You eval this again. It works.
> The third time, though, it lands you in the debugger. The very same code.
> Why the third time? And, why the debugger?  ii is well set every time it is
> used.
>
> That was bug (b). That's clearly an emacs bug?
>
>
> Here's (c) -
>
> The third time, change every "ii" to "var" ,and change every "old_ii" to
> "old_var".
> And, evaluate it.
> We still get the very same error, but the error involves ii, not var. The
> code we are defining and eval'ing has no "ii" whatsoever. It should have
> forgotten the old mac that involved ii. We defined a new mac involving
> "var."
>
>
>>
>>