Accessor macro-function

Syntax:

macro-function symbol &optional environment function

If it's an error to supply the environment argument here, the syntax shouldn't show it. Compare w/COMPILER-MACRO-FUNCTION. --sjl 5 Mar 92 \Defsetf macro-function {symbol {\opt} environment} {new-function} \Defsetf macro-function {symbol} {new-function} Reinstated per X3J13.

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

Arguments and Values:

symbol—a symbol.

environment—an environment object.

function—a macro function or nil.

new-function—a macro function.

Description:

8.1.0 2Determines 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.

The consequences are undefined if \param{environment} is supplied in a use of \funref{macro-function} as a \macref{setf} location specifier.

This doesn't belong here. -kmp 09-Apr-91 \issue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC} The \term{environment} \term{object} has \term{dynamic extent}; the consequences are undefined if the \keyref{environment} argument is referred to outside the \term{dynamic extent} of the macro expansion function. \endissue{MACRO-ENVIRONMENT-EXTENT:DYNAMIC}

The following will be deleted: 8.1.0 4 \funref{macro-function} cannot be used to determine whether \param{symbol} names a locally defined macro established by \specref{macrolet}; or \specref{symbol-macrolet} \funref{macro-function} can examine only global definitions.

8.1.0 3It 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.

Examples:

 (defmacro macfun (x) '(macro-function 'macfun)) → MACFUN 
 (not (macro-function 'macfun)) → false 
;;--- The next four lines are not valid Common Lisp, as equal ;;--- is not defined for functions --Moon (and (setf (macro-function 'macfun) #'equal) (equal (macro-function 'macfun) #'equal)) \EV \term{true} (macrolet ((macfun (x) "local")) (equal (macro-function 'macfun) #'equal)) \EV \term{true}
 (macrolet ((foo (&environment env)
               (if (macro-function 'bar env)
                  ''yes
                  ''no)))
    (list (foo)
          (macrolet ((bar () :beep))
             (foo))))
 
→ (NO YES)

Affected By:

(setf macro-function), defmacro, and macrolet.

Exceptional Situations:

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

See Also:

defmacro, Section 3.1 (Evaluation)

Notes:

8.1.0 5setf 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.