Common Lisp the Language 2nd Edition


next up previous contents index
Next: Macro Expansion Up: Macros Previous: Macros

8.1. Macro Definition

The function macro-function determines whether a given symbol is the name of a macro. The defmacro construct provides a convenient way to define new macros.

old_change_begin

[Function]
macro-function symbol

The argument must be a symbol. If the symbol has a global function definition that is a macro definition then the expansion function (a function of two arguments the macro-call form and an environment) is returned. If the symbol has no global function definition or has a definition as an ordinary function or as a special form but not as a macro then nil is returned. The function macroexpand is the best way to invoke the expansion function.

It is possible for both macro-function and special-form-p to be true of a symbol. This is possible because an implementation is permitted to implement any macro also as a special form for speed. On the other hand the macro definition must be available for use by programs that understand only the standard special forms listed in table 5-1.

macro-function cannot be used to determine whether a symbol names a locally defined macro established by macrolet; macro-function can examine only global definitions.

setf may be used with macro-function to install a macro as a symbol's global function definition:

(setf (macro-function symbol) fn)

The value installed must be a function that accepts two arguments The value installed must be a function that accepts two argumentsbol namesm-pf the symbol has a global function definition744 H