1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/m_defi_1.htm
2024-04-01 10:24:07 +02:00

73 lines
7 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: Macro DEFINE-SYMBOL-MACRO</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="f_mexp_.htm">
<LINK REL=UP HREF="c_evalua.htm">
<LINK REL=NEXT HREF="s_symbol.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="f_mexp_.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="s_symbol.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="define-symbol-macro"><I>Macro</I> <B>DEFINE-SYMBOL-MACRO</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>define-symbol-macro</B> <I>symbol expansion</I><P> =&gt; <I>symbol</I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>symbol</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A>. <P>
<I>expansion</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>. <P>
<P><B>Description:</B><P>
<P>
Provides a mechanism for globally affecting the <A REL=DEFINITION HREF="26_glo_m.htm#macro_expansion"><I>macro expansion</I></A> of the indicated <I>symbol</I>. <P>
Globally establishes an expansion function for the <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A> named by <I>symbol</I>. The only guaranteed property of an expansion <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> for a <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A> is that when it is applied to the <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> and the <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environment</I></A> it returns the correct expansion. (In particular, it is <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A> whether the expansion is conceptually stored in the expansion function, the <A REL=DEFINITION HREF="26_glo_e.htm#environment"><I>environment</I></A>, or both.) <P>
Each global reference to <I>symbol</I> (i.e., not <I>shadowed</I>[2] by a <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> for a <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A> or <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A> named by the same <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A>) is expanded by the normal macro expansion process; see <A REL=CHILD HREF="03_abaa.htm">Section 3.1.2.1.1 (Symbols as Forms)</A>. The expansion of a <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A> is subject to further <A REL=DEFINITION HREF="26_glo_m.htm#macro_expansion"><I>macro expansion</I></A> in the same <A REL=DEFINITION HREF="26_glo_l.htm#lexical_environment"><I>lexical environment</I></A> as the <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A> reference, exactly analogous to normal <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macros</I></A>. <P>
The consequences are unspecified if a <A REL=DEFINITION HREF="d_specia.htm#special"><B>special</B></A> declaration is made for <I>symbol</I> while in the scope of this definition (i.e., when it is not <I>shadowed</I>[2] by a <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> for a <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variable</I></A> or <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A> named by the same <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A>). <P>
Any use of <A REL=DEFINITION HREF="s_setq.htm#setq"><B>setq</B></A> to set the value of the <I>symbol</I> while in the scope of this definition is treated as if it were a <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A>. <A REL=DEFINITION HREF="m_psetq.htm#psetq"><B>psetq</B></A> of <I>symbol</I> is treated as if it were a <A REL=DEFINITION HREF="m_setf_.htm#psetf"><B>psetf</B></A>, and <A REL=DEFINITION HREF="m_mult_2.htm#multiple-value-setq"><B>multiple-value-setq</B></A> is treated as if it were a <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> of <A REL=DEFINITION HREF="f_values.htm#values"><B>values</B></A>. <P>
A <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>binding</I></A> for a <A REL=DEFINITION HREF="26_glo_s.htm#symbol_macro"><I>symbol macro</I></A> can be <I>shadowed</I>[2] by <A REL=DEFINITION HREF="s_let_l.htm#let"><B>let</B></A> or <A REL=DEFINITION HREF="s_symbol.htm#symbol-macrolet"><B>symbol-macrolet</B></A>. <P>
<P><B>Examples:</B><P>
<P>
<PRE>
(defvar *things* (list 'alpha 'beta 'gamma)) =&gt; *THINGS*
(define-symbol-macro thing1 (first *things*)) =&gt; THING1
(define-symbol-macro thing2 (second *things*)) =&gt; THING2
(define-symbol-macro thing3 (third *things*)) =&gt; THING3
thing1 =&gt; ALPHA
(setq thing1 'ONE) =&gt; ONE
*things* =&gt; (ONE BETA GAMMA)
(multiple-value-setq (thing2 thing3) (values 'two 'three)) =&gt; TWO
thing3 =&gt; THREE
*things* =&gt; (ONE TWO THREE)
(list thing2 (let ((thing2 2)) thing2)) =&gt; (TWO 2)
</PRE>
</TT> <P>
<P><B>Affected By:</B> None.
<P>
<P><B>Exceptional Situations:</B><P>
<P>
If <I>symbol</I> is already defined as a <A REL=DEFINITION HREF="26_glo_g.htm#global_variable"><I>global variable</I></A>, an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_progra.htm#program-error"><B>program-error</B></A> is signaled. <P>
<P><B>See Also:</B><P>
<P>
<A REL=DEFINITION HREF="s_symbol.htm#symbol-macrolet"><B>symbol-macrolet</B></A>, <A REL=DEFINITION HREF="f_mexp_.htm#macroexpand"><B>macroexpand</B></A> <P>
<P><B>Notes:</B> None.
<P>
<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>