unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* An MRE or other hints for this macro / dynamic scoping bug?
@ 2023-11-05 19:57 Dave Goel
  2023-11-05 20:04 ` Andreas Schwab
  2023-11-05 20:07 ` Stefan Kangas
  0 siblings, 2 replies; 5+ messages in thread
From: Dave Goel @ 2023-11-05 19:57 UTC (permalink / raw)
  To: emacs-devel, Dave Goel

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

Hey Emacsers,

I'm likely losing my mind. Is this not a bug, below?

I tried discussing on #emacs first, and then reported (a slightly more
complex version). But, it's perhaps not obvious, and it  was suggested I
try to produce a simpler example.

I realize I should have discussed it here first, before reporting it.  A
discussion here would probably produce a much better bug report in any
case.

Do you guys see an obvious bug here? Any simpler versions you can think
of?  Any hints where the bug could lie?

Basically, I define a macro that hardcodes the value of our variable ii
that existed before the macro definition.

And, then try to use it.


(progn
  (setq lexical-binding nil)

  (dotimes (ii 10)
    (defmacro mac ()
      `(message "%S" ,ii)
      )
    (mac)))


That's the code.
Eval it once. Works.
Eval it again. Works.

Eval it the third time. Debugger entered. Tested in emacs -Q in 28 and 29.
[[a]]

In fact, before you eval it the third time, if you change ii to jj, it
still complains about ii. [[b]]

Bugs are the behaviors  (a) and (b) above.

The macro expands to (list 'message "%S" ii). That should have worked,
right? Because ii was already set at the time of definition?

Here's the debugger behavior -
Debugger entered--Lisp error: (void-variable ii)
  (list 'message "%S" ii)

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-05 20:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-05 19:57 An MRE or other hints for this macro / dynamic scoping bug? Dave Goel
2023-11-05 20:04 ` Andreas Schwab
2023-11-05 20:12   ` Dave Goel
2023-11-05 20:50     ` Andreas Schwab
2023-11-05 20:07 ` Stefan Kangas

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).