User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cl:variables:star-macroexpand-hook-star [2017/05/01 21:00] (current)
Line 1: Line 1:
 +====== Variable *MACROEXPAND-HOOK* ======
 +
 +====Value Type====
 +a //​[[CL:​Glossary:​designator]]//​ for a //​[[CL:​Glossary:​function]]//​ of three //​[[CL:​Glossary:​argument|arguments]]//:​ a //​[[CL:​Glossary:​macro function]]//,​ a //​[[CL:​Glossary:​macro form]]//, and an //​[[CL:​Glossary:​environment]]//​ //​[[CL:​Glossary:​object]]//​.
 +
 +====Initial Value====
 +a //​[[CL:​Glossary:​designator]]//​ for a function that is equivalent to the function **[[CL:​Functions:​funcall]]**,​ but that might have additional //​[[CL:​Glossary:​implementation-dependent]]//​ side-effects.
 +
 +====Description====
 +Used as the expansion interface hook by **[[CL:​Functions:​macroexpand-1]]** to control the //​[[CL:​Glossary:​macro expansion]]//​ process. When a //​[[CL:​Glossary:​macro form]]// is to be expanded, this //​[[CL:​Glossary:​function]]//​ is called with three arguments: the //​[[CL:​Glossary:​macro function]]//,​ the //​[[CL:​Glossary:​macro form]]//, and the //​[[CL:​Glossary:​environment]]//​ in which the //​[[CL:​Glossary:​macro form]]// is to be expanded.
 +
 +The //​[[CL:​Glossary:​environment]]//​ //​[[CL:​Glossary:​object]]//​ has //​[[CL:​Glossary:​dynamic extent]]//; the consequences are undefined if the //​[[CL:​Glossary:​environment]]//​ //​[[CL:​Glossary:​object]]//​ is referred to outside the //​[[CL:​Glossary:​dynamic extent]]// of the macro expansion function.
 +
 +
 +====Examples====
 +<​blockquote>​
 +([[CL:​Macros:​defun]] hook (expander form env)
 +  ([[CL:​Functions:​format]] [[CL:​Constant Variables:​t]] "Now expanding: ~S~ ([[CL:​Functions:​funcall]] expander form env)) <​r>​HOOK</​r>​
 +
 +([[CL:​Macros:​defmacro]] machook (x y)
 +  `([[CL:​Functions:​math-divide|/​]] ([[CL:​Functions:​math-add|+]] ,x ,y) 2)) <​r>​MACHOOK</​r>​
 +  ​
 +([[CL:​Functions:​macroexpand]] '​(machook 1 2)) 
 +<​r>​([[CL:​Functions:​math-divide|/​]] ([[CL:​Functions:​math-add|+]] 1 2) 2)
 +//​[[CL:​Glossary:​true]]//​ </r>
 +
 +([[CL:​Special Operators:​let]] ((*macroexpand-hook* #'​hook))
 +  ([[CL:​Functions:​macroexpand]] '​(machook 1 2)))
 +<​o>​Now expanding (MACHOOK 1 2) </o>
 +<​r>​([[CL:​Functions:​math-divide|/​]] ([[CL:​Functions:​math-add|+]] 1 2) 2)
 +//​[[CL:​Glossary:​true]]//</​r>​
 +</​blockquote>​
 +
 +====Affected By====
 +None.
 +
 +====See Also====
 +**[[CL:​Functions:​macroexpand|Function MACROEXPAND]]**,​ **[[CL:​Functions:​macroexpand-1|Function MACROEXPAND-1]]**,​ **[[CL:​Functions:​funcall|Function FUNCALL]]**,​ {\secref\Evaluation}
 +
 +====Notes====
 +The net effect of the chosen initial value is to just invoke the //​[[CL:​Glossary:​macro function]]//,​ giving it the //​[[CL:​Glossary:​macro form]]// and //​[[CL:​Glossary:​environment]]//​ as its two arguments.
 +
 +Users or user programs can //​[[CL:​Glossary:​assign]]//​ this //​[[CL:​Glossary:​variable]]//​ to customize or trace the //​[[CL:​Glossary:​macro expansion]]//​ mechanism. Note, however, that this //​[[CL:​Glossary:​variable]]//​ is a global resource, potentially shared by multiple //​[[CL:​Glossary:​programs]]//;​ as such, if any two //​[[CL:​Glossary:​programs]]//​ depend for their correctness on the setting of this //​[[CL:​Glossary:​variable]]//,​ those //​[[CL:​Glossary:​programs]]//​ may not be able to run in the same //​[[CL:​Glossary:​Lisp image]]//. For this reason, it is frequently best to confine its uses to debugging situations.
 +
 +Users who put their own function into **[[CL:​Variables:​*macroexpand-hook*]]** should consider saving the previous value of the hook, and calling that value from their own.
 +
 +\issue{MACROEXPAND-HOOK-INITIAL-VALUE:​IMPLEMENTATION-DEPENDENT} \issue{FUNCTION-TYPE:​X3J13-MARCH-88} \issue{MACROEXPAND-HOOK-DEFAULT:​EXPLICITLY-VAGUE} \issue{MACROEXPAND-HOOK-INITIAL-VALUE:​IMPLEMENTATION-DEPENDENT} \issue{MACRO-ENVIRONMENT-EXTENT:​DYNAMIC}