Next: Defining Macros Prev: Expansion Up: Macros
Macros and Byte Compilation
You might ask why we take the trouble to compute an expansion for a
macro and then evaluate the expansion. Why not have the macro body
produce the desired results directly? The reason has to do with
When a macro call appears in a Lisp program being compiled, the Lisp
compiler calls the macro definition just as the interpreter would, and
receives an expansion. But instead of evaluating this expansion, it
compiles the expansion as if it had appeared directly in the program.
As a result, the compiled code produces the value and side effects
intended for the macro, but executes at full compiled speed. This would
not work if the macro body computed the value and side effects
itself--they would be computed at compile time, which is not useful.
In order for compilation of macro calls to work, the macros must be
defined in Lisp when the calls to them are compiled. The compiler has a
special feature to help you do this: if a file being compiled contains a
`defmacro' form, the macro is defined temporarily for the rest of the
compilation of that file. To use this feature, you must define the
macro in the same file where it is used and before its first use.
While byte-compiling a file, any `require' calls at top-level are
executed. One way to ensure that necessary macro definitions are
available during compilation is to require the file that defines them.
automatically generated by info2www