61 lines
7.3 KiB
HTML
61 lines
7.3 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: Variable *MACROEXPAND-HOOK*</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="s_symbol.htm">
|
|
<LINK REL=UP HREF="c_evalua.htm">
|
|
<LINK REL=NEXT HREF="f_procla.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="s_symbol.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_evalua.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_procla.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="STmacroexpand-hookST"><I>Variable</I> <B>*MACROEXPAND-HOOK*</B></A> <P>
|
|
<P>
|
|
<P><B>Value Type:</B><P>
|
|
<P>
|
|
a <A REL=DEFINITION HREF="26_glo_d.htm#designator"><I>designator</I></A> for a <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> of three <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>arguments</I></A>: a <A REL=DEFINITION HREF="26_glo_m.htm#macro_function"><I>macro function</I></A>, a <A REL=DEFINITION HREF="26_glo_m.htm#macro_form"><I>macro form</I></A>, and an <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environment</I></A> <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
|
|
<P><B>Initial Value:</B><P>
|
|
<P>
|
|
a <A REL=DEFINITION HREF="26_glo_d.htm#designator"><I>designator</I></A> for a function that is equivalent to the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="f_funcal.htm#funcall"><B>funcall</B></A>, but that might have additional <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A> side-effects. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
Used as the expansion interface hook by <A REL=DEFINITION HREF="f_mexp_.htm#macroexpand-1"><B>macroexpand-1</B></A> to control the <A REL=DEFINITION HREF="26_glo_m.htm#macro_expansion"><I>macro expansion</I></A> process. When a <A REL=DEFINITION HREF="26_glo_m.htm#macro_form"><I>macro form</I></A> is to be expanded, this <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> is called with three arguments: the <A REL=DEFINITION HREF="26_glo_m.htm#macro_function"><I>macro function</I></A>, the <A REL=DEFINITION HREF="26_glo_m.htm#macro_form"><I>macro form</I></A>, and the <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environment</I></A> in which the <A REL=DEFINITION HREF="26_glo_m.htm#macro_form"><I>macro form</I></A> is to be expanded. The <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environment</I></A> <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A> has <A REL=DEFINITION HREF="26_glo_d.htm#dynamic_extent"><I>dynamic extent</I></A>; the consequences are undefined if the <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environment</I></A> <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A> is referred to outside the <A REL=DEFINITION HREF="26_glo_d.htm#dynamic_extent"><I>dynamic extent</I></A> of the macro expansion function. <P>
|
|
<P><B>Examples:</B><P>
|
|
<P>
|
|
<PRE>
|
|
(defun hook (expander form env)
|
|
(format t "Now expanding: ~S~%" form)
|
|
(funcall expander form env)) => HOOK
|
|
(defmacro machook (x y) `(/ (+ ,x ,y) 2)) => MACHOOK
|
|
(macroexpand '(machook 1 2)) => (/ (+ 1 2) 2), <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
|
|
(let ((*macroexpand-hook* #'hook)) (macroexpand '(machook 1 2)))
|
|
>> Now expanding (MACHOOK 1 2)
|
|
=> (/ (+ 1 2) 2), <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Affected By:</B> None.
|
|
<P>
|
|
<P><B>See Also:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="f_mexp_.htm#macroexpand"><B>macroexpand</B></A>, <A REL=DEFINITION HREF="f_mexp_.htm#macroexpand-1"><B>macroexpand-1</B></A>, <A REL=DEFINITION HREF="f_funcal.htm#funcall"><B>funcall</B></A>, <A REL=CHILD HREF="03_a.htm">Section 3.1 (Evaluation)</A> <P>
|
|
<P><B>Notes:</B><P>
|
|
<P>
|
|
The net effect of the chosen initial value is to just invoke the <A REL=DEFINITION HREF="26_glo_m.htm#macro_function"><I>macro function</I></A>, giving it the <A REL=DEFINITION HREF="26_glo_m.htm#macro_form"><I>macro form</I></A> and <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environment</I></A> as its two arguments. <P>
|
|
Users or user programs can <A REL=DEFINITION HREF="26_glo_a.htm#assign"><I>assign</I></A> this <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A> to customize or trace the <A REL=DEFINITION HREF="26_glo_m.htm#macro_expansion"><I>macro expansion</I></A> mechanism. Note, however, that this <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A> is a global resource, potentially shared by multiple <A REL=DEFINITION HREF="26_glo_p.htm#program"><I>programs</I></A>; as such, if any two <A REL=DEFINITION HREF="26_glo_p.htm#program"><I>programs</I></A> depend for their correctness on the setting of this <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A>, those <A REL=DEFINITION HREF="26_glo_p.htm#program"><I>programs</I></A> may not be able to run in the same <A REL=DEFINITION HREF="26_glo_l.htm#lisp_image"><I>Lisp image</I></A>. For this reason, it is frequently best to confine its uses to debugging situations. <P>
|
|
Users who put their own function into <A REL=DEFINITION HREF="#STmacroexpand-hookST"><B>*macroexpand-hook*</B></A> should consider saving the previous value of the hook, and calling that value from their own. <P>
|
|
<P>
|
|
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss229.htm">MACRO-ENVIRONMENT-EXTENT:DYNAMIC</A><LI> <A REL=CHILD HREF="../Issues/iss234.htm">MACROEXPAND-HOOK-INITIAL-VALUE:IMPLEMENTATION-DEPENDENT</A><LI> <A REL=CHILD HREF="../Issues/iss233.htm">MACROEXPAND-HOOK-DEFAULT:EXPLICITLY-VAGUE</A><LI> <A REL=CHILD HREF="../Issues/iss179.htm">FUNCTION-TYPE:X3J13-MARCH-88</A><P></UL><HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|