Closed davidmullen closed 6 months ago
define-symbol-macro
already wraps the output of its expansion in an eval-when
, just not the one you expect. It currently lacks the :compile-toplevel
part. I would also be inclined to consider this a bug and a (explainable) specification oversight.
BTW, define-compiler-macro
seems to suffer from the same condition as define-symbol-macro
, not so surprising since they share much of the same development history.
Would you say that it too should be :compile-toplevel
?
Yes, I noticed that about define-compiler-macro
. I suppose the difference is that compiler macros aren't required by the standard to be expanded at all. But it's natural to expect a compiler macro to have a compile-time effect, particularly if the compiler macro is defined in the same file as the function that the compiler macro is for. So it appears typical for Common Lisp implementations to have :compile-toplevel
in define-compiler-macro
.
How about what I just put on master/head (commit e517c6d). If that looks good to you it should close the issue.
This works interpreted:
But the compiler gives a warning:
And the symbol macro isn't expanded:
It works with an
eval-when
:I don't know if this is a matter of ANSI compliance, but it seems better—i.e. less surprising—if the compiler treats symbol macros the same way as regular macros. The standard says that for
defmacro
, "the compiler must store the macro definition at compile time, so that occurrences of the macro later on in the file can be expanded correctly." Fordefine-symbol-macro
, the standard doesn't say that, but it would seem to be implied.