GNU Info

Info Node: (librep.info)Compiling Macros

(librep.info)Compiling Macros


Prev: Macro Expansion Up: Macros
Enter node , (file) or (file)node

Compiling Macros
----------------

   Although it may seem odd that macros return a form to produce a
result and not simply the result itself, this is actually their most
important feature. It allows the expansion and the evaluation of the
expansion to occur at different times.

   The Lisp compiler makes use of this; when it comes across a macro
call in a form it is compiling it uses the `macroexpand' function to
produce the expansion of that form. This expansion is then compiled
straight into the object code. Obviously this is good for performance
(why evaluate the expansion every time it is needed when once will do?).

   Some rules do need to be observed to make this work properly:

   * The macro expansion function (i.e. the definition of the macro)
     should not have any side effects or evaluate its arguments (the
     value of a symbol at compile-time probably won't be the same as
     its value at run-time).

   * Macros which are defined by another file must be loaded so they
     can be recognised. Use the `require' function, the compiler will
     evaluate any `require' forms it sees loading any macro definitions
     used.

   Note however, that the `librep' compiler does allow macros to be
used before they are defined (two passes are made through the source
file).


automatically generated by info2www version 1.2.2.9