Compiler Macros (original) (raw)
ANSI Common Lisp 3 Evaluation and Compilation
3.2 Compilation
3.2.2 Compilation Semantics
3.2.2.1 Compiler Macros
A compiler macro can be defined for a namethat also names a function or macro. That is, it is possible for afunction name to name both a function and a compiler macro.
A function name names a compiler macro if compiler-macro-functionis true of the function name in the lexical environment in which it appears. Creating a lexical binding for the function namenot only creates a new local function ormacro definition, but also _shadows_2 the compiler macro.
The function returned by compiler-macro-functionis a function of two arguments, called the expansion function. To expand a compiler macro, the expansion function is invoked by calling the macroexpand hook with the expansion function as its first argument, the entire compiler macro form as its second argument, and the current compilation environment (or with the current lexical environment, if the form is being processed by something other than compile-file) as its third argument. The macroexpand hook, in turn, calls the expansion function with the_form_ as its first argument and the environment as its second argument. The return value from the expansion function, which is passed through by the macroexpand hook, might either be the same form, or else a form that can, at the discretion of the code doing the expansion, be used in place of the original form.
Defined names applicable to compiler macros
*macroexpand-hook* | compiler-macro-function | define-compiler-macro |
---|
3.2.2.1.1 Purpose of Compiler Macros
3.2.2.1.2 Naming of Compiler Macros
3.2.2.1.3 When Compiler Macros Are Used