56 lines
6.8 KiB
HTML
56 lines
6.8 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: Section 3.2.3.1.1</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="03_bca.htm">
|
|
<LINK REL=UP HREF="03_bca.htm">
|
|
<LINK REL=NEXT HREF="03_bcab.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="03_bca.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="03_bca.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="03_bcab.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<H2>
|
|
3.2.3.1.1 Processing of Defining Macros</H2> <P>
|
|
<P>
|
|
Defining <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macros</I></A> (such as <A REL=DEFINITION HREF="m_defmac.htm#defmacro"><B>defmacro</B></A> or <A REL=DEFINITION HREF="m_defpar.htm#defvar"><B>defvar</B></A>) appearing within a file being processed by <A REL=DEFINITION HREF="f_cmp_fi.htm#compile-file"><B>compile-file</B></A> normally have compile-time side effects which affect how subsequent <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> in the same <A REL=DEFINITION HREF="26_glo_f.htm#file"><I>file</I></A> are compiled. A convenient model for explaining how these side effects happen is that the defining macro expands into one or more <A REL=DEFINITION HREF="s_eval_w.htm#eval-when"><B>eval-when</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A>, and that the calls which cause the compile-time side effects to happen appear in the body of an <TT>(eval-when (:compile-toplevel) ...)</TT> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>. <P>
|
|
The compile-time side effects may cause information about the definition to be stored differently than if the defining macro had been processed in the `normal' way (either interpretively or by loading the compiled file). <P>
|
|
In particular, the information stored by the defining <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macros</I></A> at compile time might or might not be available to the interpreter (either during or after compilation), or during subsequent calls to the <A REL=DEFINITION HREF="26_glo_c.htm#compiler"><I>compiler</I></A>. For example, the following code is nonportable because it assumes that the <A REL=DEFINITION HREF="26_glo_c.htm#compiler"><I>compiler</I></A> stores the macro definition of <TT>foo</TT> where it is available to the interpreter: <P>
|
|
<PRE>
|
|
(defmacro foo (x) `(car ,x))
|
|
(eval-when (:execute :compile-toplevel :load-toplevel)
|
|
(print (foo '(a b c))))
|
|
</PRE>
|
|
</TT> <P>
|
|
A portable way to do the same thing would be to include the macro definition inside the <A REL=DEFINITION HREF="s_eval_w.htm#eval-when"><B>eval-when</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>, as in: <P>
|
|
<PRE>
|
|
(eval-when (:execute :compile-toplevel :load-toplevel)
|
|
(defmacro foo (x) `(car ,x))
|
|
(print (foo '(a b c))))
|
|
</PRE>
|
|
</TT> <P>
|
|
<P>
|
|
The next figure lists macros that make definitions available both in the compilation and run-time <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environments</I></A>. It is not specified whether definitions made available in the <A REL=DEFINITION HREF="26_glo_c.htm#compilation_environment"><I>compilation environment</I></A> are available in the evaluation <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environment</I></A>, nor is it specified whether they are available in subsequent compilation units or subsequent invocations of the compiler. As with <A REL=DEFINITION HREF="s_eval_w.htm#eval-when"><B>eval-when</B></A>, these compile-time side effects happen only when the defining macros appear at top level. <P>
|
|
<PRE>
|
|
<A REL=DEFINITION HREF="m_declai.htm#declaim">declaim</A> <A REL=DEFINITION HREF="m_defi_2.htm#define-modify-macro">define-modify-macro</A> <A REL=DEFINITION HREF="m_defset.htm#defsetf">defsetf</A>
|
|
<A REL=DEFINITION HREF="m_defcla.htm#defclass">defclass</A> <A REL=DEFINITION HREF="m_defi_3.htm#define-setf-expander">define-setf-expander</A> <A REL=DEFINITION HREF="m_defstr.htm#defstruct">defstruct</A>
|
|
<A REL=DEFINITION HREF="m_defcon.htm#defconstant">defconstant</A> <A REL=DEFINITION HREF="m_defmac.htm#defmacro">defmacro</A> <A REL=DEFINITION HREF="m_deftp.htm#deftype">deftype</A>
|
|
<A REL=DEFINITION HREF="m_define.htm#define-compiler-macro">define-compiler-macro</A> <A REL=DEFINITION HREF="m_defpkg.htm#defpackage">defpackage</A> <A REL=DEFINITION HREF="m_defpar.htm#defvar">defvar</A>
|
|
<A REL=DEFINITION HREF="m_defi_5.htm#define-condition">define-condition</A> <A REL=DEFINITION HREF="m_defpar.htm#defparameter">defparameter</A>
|
|
</PRE>
|
|
<P><B>Figure 3-8. Defining Macros That Affect the Compile-Time Environment</B> <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/iss051.htm">CLOS-MACRO-COMPILATION:MINIMAL</A><LI> <A REL=CHILD HREF="../Issues/iss101.htm">DEFINE-COMPILER-MACRO:X3J13-NOV89</A><LI> <A REL=CHILD HREF="../Issues/iss278.htm">PROCLAIM-ETC-IN-COMPILE-FILE:NEW-MACRO</A><LI> <A REL=CHILD HREF="../Issues/iss308.htm">SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS</A><LI> <A REL=CHILD HREF="../Issues/iss059.htm">COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY</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>
|