MACRO-FUNCTION(3cl)

Common Lisp Reference

MACRO-FUNCTION(3cl)

 

NAME

macro-function – return macro expansion function (accessor)

SYNOPSIS

 

macro-function symbol &optional environment
function

( 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

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.

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.    

NOTES

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.    

EXAMPLES

( defmacro macfun ( x ) ’( macro-function macfun )) MACFUN   
( not ( macro-function macfun )) false    

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

SEE ALSO

defmacro(3cl)    

AUTHOR and COPYRIGHT

Substantial portions of this page are taken from draft proposed American National Standard for Information Systems—Programming Language—Common Lisp, X3J13/94-101R, Version 15.17R, Fri 12-Aug-1994 6:35pm EDT; no copyright indicated.

Additional clarification and comments by Michael Marking <marking@tatanka.com>, http://www.tatanka.com/software/cl-manpages/; alternatively, https://github.com/wakinyantanka/cl-manpages/. Copyright 2017 Michael Marking as both an original and a derivative work.

Licensed under Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0).

This page last revised Sunday 26 February 2017.