User Tools



  • macro-function symbol &optional environmentfunction
  • (setf (macro-function symbol &optional environment) new-function)

Arguments and Values


Determines whether symbol has a function definition as a macro in the specified environment.

If so, the macro expansion function, a function of two arguments, is returned. If symbol has no function definition in the lexical environment environment, or its definition is not a macro, macro-function returns nil.

It is possible for both macro-function and special-operator-p to return true of symbol. The macro definition must be available for use by programs that understand only the standard Common Lisp special forms.


(defmacro macfun (x) '(macro-function 'macfun))


(not (macro-function 'macfun))


(macrolet ((foo (&environment env) (if (macro-function 'bar env) yes no))) (list (foo) (macrolet ((bar () :beep)) (foo))))


Affected By

Exceptional Situations

The consequences are undefined if environment is non-nil in a use of setf of macro-function.

See Also

Macro DEFMACRO, {\secref\Evaluation}


setf can 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 entire macro call and an environment, and computes the expansion for that call. Performing this operation causes symbol to have only that macro definition as its global function definition; any previous definition, whether as a macro or as a function, is lost.