Uses of Macros
There are several advantages in using macros:
- Macros can extend the Lisp language by
providing ``system functions''
desired by the user. For example, the case statement
is provided as a macro.
- Macros can reduce the amount of code the user must enter for
frequently-used code idioms.
- Since a macro expands in-line as ordinary Lisp code, it does not
involve any extra function calls when used in compiled code. This makes
macro use virtually free.
- Since a macro is implemented by a function, the function can examine
how the macro is being used and produce more efficient code in some cases.
Macros can be relatively slow for interpretive use, since they may cause
construction of new code each time the macro is executed; for compiled
code, there is no penalty.