Next: , Previous: , Up: Byte Compilation   [Contents][Index]


21.6 Evaluation During Compilation

These features permit you to write code to be evaluated during compilation of a program.

Special Form: eval-and-compile body

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. Using require is preferable if there is a substantial amount of code to be executed in this way.

Special Form: eval-when-compile body

This form marks body to be evaluated at compile time and not when the compiled program is loaded. The result of evaluation by the compiler becomes a constant which appears in the compiled program. When the program is interpreted, not compiled at all, body is evaluated normally.

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 what eval-when-compile does.