Common Lisp the Language, 2nd Edition


next up previous contents index
Next: Function Calls Up: Forms Previous: Special Forms

5.1.4. Macros

If a form is a list and the first element is not the name of a special form, it may be the name of a macro; if so, the form is said to be a macro call. A macro is essentially a function from forms to forms that will, given a call to that macro, compute a new form to be evaluated in place of the macro call. (This computation is sometimes referred to as macro expansion.) For example, the macro named return will take a form such as (return x) and from that form compute a new form (return-from nil x). We say that the old form expands into the new form. The new form is then evaluated in place of the original form; the value of the new form is returned as the value of the original form.

change_begin
X3J13 voted in January 1989 (DOTTED-MACRO-FORMS)   to clarify that macro calls, and subforms of macro calls, need not be proper lists, but that use of dotted forms requires the macro definition to use ``. var'' or ``&rest var'' in order to match them properly. It is then the responsibility of the macro definition to recognize and appropriately handle such dotted forms or subforms.
change_end

There are a number of standard macros in Common Lisp, and the user can define more by using defmacro.

Macros provided by a Common Lisp implementation as described herein may expand into code that is not portable among differing implementations. That is, a macro call may be implementation-independent because the macro is defined in this book, but the expansion need not be.


Implementation note: Implementors are encouraged to implement the macros defined in this book, as far as is possible, in such a way that the expansion will not contain any implementation-dependent special forms, nor contain as forms data objects that are not considered to be forms in Common Lisp. The purpose of this restriction is to ensure that the expansion can be processed by a program-analyzing program in an implementation-independent manner. There is no problem with a macro expansion containing calls to implementation-dependent functions. This restriction is not a requirement of Common Lisp; it is recognized that certain complex macros may be able to expand into significantly more efficient code in certain implementations by using implementation-dependent special forms in the macro expansion.



next up previous contents index
Next: Function Calls Up: Forms Previous: Special Forms


AI.Repository@cs.cmu.edu