Sometimes, when debugging macros, I find it convenient to wrap a PRINT
around the macro expansion.  However, I am surprised at the following
behavior:

,----
| CL-USER> (defmacro foo () (print`(let () nil)))
| FOO
| CL-USER> (foo)
| 
| (LET ()
|   NIL) 
| (LET ()
|   NIL) 
| NIL
| CL-USER> (defmacro bar () (print `nil))
| BAR
| CL-USER> (bar)
| 
| NIL 
| NIL
`----

As you can see, a call to FOO prints the expansion twice, a call to
BAR only once.  Moreover, when gensyms are involved, in those cases
where two versions are printed, the gensyms have different numbers,
the first version is the correct expansion, and the second one always
has the same gensym numbers (and presumably the same symbols).

,----
| (WITH-NAN (#:NAN5087 :DOUBLE)
|           (MACROLET ()
|             (LET* ((#:COORD-NEW5096 (COERCE 3.0d0 'DOUBLE-FLOAT))
|                    (#:COORD-NEW5092 (COERCE 4.0d0 'DOUBLE-FLOAT))
...
|               ))) 
| (WITH-NAN (#:NAN9 :DOUBLE)
|           (MACROLET ()
|             (LET* ((#:COORD-NEW18 (COERCE 3.0d0 'DOUBLE-FLOAT))
|                    (#:COORD-NEW14 (COERCE 4.0d0 'DOUBLE-FLOAT))
...
|               ))) 
`----

This is on x86-Linux snapshot from 2004-08.  (Clisp, by the way,
always prints only once.)

Can someone shed some light on what is going on here, or point to the
relevant manual?

Thanks in advance,

Albert.

Reply via email to