FUZZ> (defvar *foo* nil)
*FOO*
FUZZ> (defmacro bar ()
(format t "foo: ~A" *foo*)
`(+ 1 1))
BAR
FUZZ> (defmacro bot ()
(let ((*foo* 17))
`(bar)))
BOT
FUZZ> (bot)
foo: NIL
My mental model (clearly wrong) of macro expansion says the following happens in order:
Run the macro expansion of bot
(which binds *foo*
to 17
), run the macro expansion of bar
, which prints the current value of *foo*
(being 17
), and returns the form (+ 1 1)
, which is not a macro, macro expansion time is now over, finally evaluate the form (+ 1 1)
, and returns 2
.
Why am I wrong?
Is there an easy way to do what I intend?