Next: Backquote, Previous: Compiling Macros, Up: Macros
A Lisp macro is a list whose car is macro. Its cdr should
be a function; expansion of the macro works by applying the function
(with apply) to the list of unevaluated argument-expressions
from the macro call.
It is possible to use an anonymous Lisp macro just like an anonymous
function, but this is never done, because it does not make sense to pass
an anonymous macro to functionals such as mapcar. In practice,
all Lisp macros have names, and they are usually defined with the
special form defmacro.
defmacrodefines the symbol name as a macro that looks like this:(macro lambda argument-list . body-forms)(Note that the cdr of this list is a function—a lambda expression.) This macro object is stored in the function cell of name. The value returned by evaluating the
defmacroform is name, but usually we ignore this value.The shape and meaning of argument-list is the same as in a function, and the keywords
&restand&optionalmay be used (see Argument List). Macros may have a documentation string, but anyinteractivedeclaration is ignored since macros cannot be called interactively.
The body of the macro definition can include a declare form,
which can specify how <TAB> should indent macro calls, and how to
step through them for Edebug.
A
declareform is used in a macro definition to specify various additional information about it. Two kinds of specification are currently supported:
(debugedebug-form-spec)- Specify how to step through macro calls for Edebug. See Instrumenting Macro Calls, for more details.
(indentindent-spec)- Specify how to indent calls to this macro. See Indenting Macros, for more details.
A
declareform only has its special effect in the body of adefmacroform if it immediately follows the documentation string, if present, or the argument list otherwise. (Strictly speaking, severaldeclareforms can follow the documentation string or argument list, but since adeclareform can have several specs, they can always be combined into a single form.) When used at other places in adefmacroform, or outside adefmacroform,declarejust returnsnilwithout evaluating any specs.
No macro absolutely needs a declare form, because that form
has no effect on how the macro expands, on what the macro means in the
program. It only affects secondary features: indentation and Edebug.