MACROEXPAND-HOOK(3cl) |
Common Lisp Reference |
MACROEXPAND-HOOK(3cl) |
NAME
macroexpand-hook – variable used to control the macro expansion process (variable)
SYNOPSIS
*macroexpand-hook*
|
ARGUMENTS and VALUES
Value Type: a designator for a function of three arguments: a macro function, a macro form, and an environment object.
Initial Value: a designator for a function that is equivalent to the function funcall, but that might have additional implementation-dependent side-effects.
DESCRIPTION
Used as the expansion interface hook by macroexpand-1 to control the macro expansion process. When a macro form is to be expanded, this function is called with three arguments: the macro function, the macro form, and the environment in which the macro form is to be expanded. The environment object has dynamic extent; the consequences are undefined if the environment object is referred to outside the dynamic extent of the macro expansion function.
AFFECTED BY
(none)
EXCEPTIONAL SITUATIONS
(none)
NOTES
The net effect of the chosen initial value is to just invoke the macro function, giving it the macro form and environment as its two arguments.
Users or user programs can assign this variable to customize or trace the macro expansion mechanism. Note, however, that this variable is a global resource, potentially shared by multiple programs; as such, if any two programs depend for their correctness on the setting of this variable, those programs may not be able to run in the same Lisp image. For this reason, it is frequently best to confine its uses to debugging situations.
Users who put their own function into *macroexpand-hook* should consider saving the previous value of the hook, and calling that value from their own.
EXAMPLES
(defun ()
(format t "Now expanding: ~S~%" )
(funcall ))
(defmacro () `(/ (+ , ,) 2))
(macroexpand ’( 1 2)) (/ (+ 1 2) 2), true
(let ((*macroexpand-hook* #’))
(macroexpand ’( 1 2)))
Now expanding (MACHOOK 1 2)
(/ (+ 1 2) 2), true
SEE ALSO
macroexpand(3cl), macroexpand-1(3cl), funcall(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.