Uses of Macros

There are several advantages in using macros:

  1. Macros can extend the Lisp language by providing ``system functions'' desired by the user. For example, the case statement is provided as a macro.

  2. Macros can reduce the amount of code the user must enter for frequently-used code idioms.

  3. 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.

  4. 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.

Contents    Page-10    Prev    Next    Page+10    Index