Next: Byte-Code Objects, Previous: Dynamic Loading, Up: Byte Compilation
These features permit you to write code to be evaluated during compilation of a program.
This form marks body to be evaluated both when you compile the containing code and when you run it (whether compiled or not).
You can get a similar result by putting body in a separate file and referring to that file with
require
. That method is preferable when body is large.
This form marks body to be evaluated at compile time but not when the compiled program is loaded. The result of evaluation by the compiler becomes a constant which appears in the compiled program. If you load the source file, rather than compiling it, body is evaluated normally.
Common Lisp Note: At top level, this is analogous to the Common Lisp idiom
(eval-when (compile eval) ...)
. Elsewhere, the Common Lisp ‘#.’ reader macro (but not when interpreting) is closer to whateval-when-compile
does.