174 lines
13 KiB
HTML
174 lines
13 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: Issue SYMBOL-MACROLET-SEMANTICS Writeup</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="../Issues/iss337_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss338.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss339_w.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="../Issues/iss337_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss338.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss339_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue SYMBOL-MACROLET-SEMANTICS Writeup</H2>
|
|
|
|
<PRE><B>Status:</B> Version 5 passed Jan 89 X3J13<P>
|
|
Version 6 passed Mar 89 X3J13<P>
|
|
<P>
|
|
<B>Issue:</B> <A HREF="iss338.htm">SYMBOL-MACROLET-SEMANTICS</A><P>
|
|
<B>References:</B> <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> (88-002R page 2-81)<P>
|
|
<P>
|
|
<P>
|
|
Related Issues: <A HREF="iss337.htm">SYMBOL-MACROLET-DECLARE</A><P>
|
|
<B>Category:</B> CHANGE<P>
|
|
<B>Edit history:</B> 29-July-88, Version 1 by Piazza<P>
|
|
21-September-88, Version 2 by Piazza<P>
|
|
22-September-88, Version 3 by Piazza <P>
|
|
22-September-88, Version 4 by Piazza<P>
|
|
30-Nov-88, Version 5 by Masinter<P>
|
|
14-Mar-89, Version 6 by Steele<P>
|
|
<P>
|
|
<B>Problem Description:<P>
|
|
</B><P>
|
|
The <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> construct, introduced with CLOS in X3J13 document<P>
|
|
88-002R, profoundly alters the interpretation of symbols appearing as<P>
|
|
forms in a Common Lisp program--what previously was necessarily a variable<P>
|
|
might now be a symbol macro instead. Macros which appear in the body of a<P>
|
|
<A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> form are currently unable to determine whether a symbol<P>
|
|
form is a variable or a symbol macro, and, if the latter, what the<P>
|
|
expansion of the symbol macro is. Consequently, complex macros (such as<P>
|
|
<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> or <A REL=DEFINITION HREF="../Body/m_push.htm#push"><B>PUSH</B></A>) which depend on the form of their argument(s), are unable to<P>
|
|
produce their desired results in some cases, as in the following example:<P>
|
|
<P>
|
|
(let ((a (<A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>make-array</B></A> 5))<P>
|
|
(i 0))<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>symbol-macrolet</B></A> ((place (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>aref</B></A> a (<A REL=DEFINITION HREF="../Body/m_incf_.htm#incf"><B>incf</B></A> i))))<P>
|
|
(push x place))<P>
|
|
i) ==> 2<P>
|
|
<P>
|
|
In addition, it would be both natural and nice to be able to write<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_w_slts.htm#with-slots"><B>with-slots</B></A> (rho theta) point<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>declare</B></A> (<A REL=DEFINITION HREF="../Body/t_short_.htm#single-float"><B>single-float</B></A> rho theta))<P>
|
|
...computation...)<P>
|
|
<P>
|
|
as well as <A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> within <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> forms.<P>
|
|
<P>
|
|
<B>Proposal (SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM):<P>
|
|
</B><P>
|
|
Change the definition of <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> to specify that it is a special<P>
|
|
form, which affects the evaluation environment for symbols. Enhance<P>
|
|
<A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand"><B>MACROEXPAND</B></A> and <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand-1"><B>MACROEXPAND-1</B></A> so that they can expand a symbol macro.<P>
|
|
Modify <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A> et al to use the new <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand"><B>MACROEXPAND</B></A> and <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand-1"><B>MACROEXPAND-1</B></A> to examine<P>
|
|
even symbol subforms. Specify that the expansion of a symbol macro IS<P>
|
|
subject to further macro expansion in the same lexical environment as the<P>
|
|
symbol macro invocation, exactly analogous to normal macros. Clarify that<P>
|
|
within the body of a <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A>, <A REL=DEFINITION HREF="../Body/s_setq.htm#setq"><B>SETQ</B></A> of a symbol defined as<P>
|
|
a symbol macro will be treated as if it were a <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A>.<P>
|
|
<P>
|
|
Furthermore <A REL=DEFINITION HREF="../Body/m_psetq.htm#psetq"><B>PSETQ</B></A> of a symbol defined as a symbol macro will<P>
|
|
behave as if it were a <A REL=DEFINITION HREF="../Body/m_setf_.htm#psetf"><B>PSETF</B></A>, and <A REL=DEFINITION HREF="../Body/m_mult_2.htm#multiple-value-setq"><B>MULTIPLE-VALUE-SETQ</B></A> will behave<P>
|
|
as if <A REL=DEFINITION HREF="../Body/s_setq.htm#setq"><B>SETQ</B></A> were used on each variable to be set.<P>
|
|
<P>
|
|
When <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand"><B>MACROEXPAND</B></A> or <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand-1"><B>MACROEXPAND-1</B></A> sees a symbol macro, it calls<P>
|
|
the value of <A REL=DEFINITION HREF="../Body/v_mexp_h.htm#STmacroexpand-hookST"><B>*MACROEXPAND-HOOK*</B></A> in the same manner as for an<P>
|
|
ordinary macro. The three values given to the hook function<P>
|
|
in this case will be an expansion function, a form (in this case<P>
|
|
the symbol naming the symbol macro), and an environment. The<P>
|
|
only guaranteed property of the expansion function is that when<P>
|
|
it is applied to the form and the environment it will return the<P>
|
|
correct expansion of the symbol macro. (In particular, nothing<P>
|
|
it said in this specification whether the expansion is conceptually<P>
|
|
stored in the expansion function, the environment, or both.)<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B><P>
|
|
The potential for interaction between macros is exactly why &environment<P>
|
|
arguments were originally added to macros. Changing <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> to be<P>
|
|
a special form, which communicates through the &environment arguments to<P>
|
|
macros with <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand"><B>MACROEXPAND</B></A> and <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand-1"><B>MACROEXPAND-1</B></A>, would allow <A REL=DEFINITION HREF="../Body/m_push.htm#push"><B>PUSH</B></A> and <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A><P>
|
|
(among others) to work with <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> in the same way they work with<P>
|
|
<A REL=DEFINITION HREF="../Body/s_flet_.htm#macrolet"><B>MACROLET</B></A>.<P>
|
|
<P>
|
|
This change cannot (reasonably) support the currently specified semantics<P>
|
|
that the expansion text is "outside" the scope of the symbol macro. For<P>
|
|
indeed, when the symbol macro is expanded, (a copy of) the expansion is<P>
|
|
then within the scope of the <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A>, and should then be subject<P>
|
|
to further scrutiny. The issue of "infinite expansion" of symbol macros is<P>
|
|
no more dangerous than that of normal macros.<P>
|
|
<P>
|
|
<B>Current Practice:<P>
|
|
</B><P>
|
|
Portable Common Loops provides a code-walking implementation of<P>
|
|
<A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> as specified in 88-002R. Symbolics Cloe has both a<P>
|
|
code-walking version of a <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> macro and compiler support for<P>
|
|
a <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> special form.<P>
|
|
<P>
|
|
<B>Cost to Implementors:<P>
|
|
</B><P>
|
|
If <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> is modified to be a special form, compilers and<P>
|
|
interpreters will have to change, as well as <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand"><B>MACROEXPAND</B></A>, <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand-1"><B>MACROEXPAND-1</B></A>,<P>
|
|
<A REL=DEFINITION HREF="../Body/m_push.htm#push"><B>PUSH</B></A>, <A REL=DEFINITION HREF="../Body/m_incf_.htm#incf"><B>INCF</B></A>, <A REL=DEFINITION HREF="../Body/m_incf_.htm#decf"><B>DECF</B></A>, and others.<P>
|
|
<P>
|
|
<B>Cost to Users:<P>
|
|
</B><P>
|
|
If <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> is converted to a special form, code-walking programs<P>
|
|
will have to be modified to handle <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> correctly. Those same<P>
|
|
programs would have to be modified to handle the other special forms<P>
|
|
specified in CLOS, anyway.<P>
|
|
<P>
|
|
<B>Cost of Non-Adoption:<P>
|
|
</B><P>
|
|
<A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> will retain its confusing semantics, leading to bugs when<P>
|
|
it interacts with complex macros and forms which produce side-effects.<P>
|
|
<P>
|
|
Implementations which support ONCE-ONLY will break. For that matter, any<P>
|
|
mechanism which examines code and assumes that "variables" have no side<P>
|
|
effects will break.<P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B><P>
|
|
<A HREF="iss338.htm">SYMBOL-MACROLET-SEMANTICS:SPECIAL-FORM</A> avoids the hairiest problems<P>
|
|
surrounding interaction of macros (like <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A>) and side effects, and makes<P>
|
|
<A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> consistent with <A REL=DEFINITION HREF="../Body/s_flet_.htm#macrolet"><B>MACROLET</B></A>.<P>
|
|
<P>
|
|
<B>Aesthetics:<P>
|
|
</B><P>
|
|
If <A REL=DEFINITION HREF="../Body/s_symbol.htm#symbol-macrolet"><B>SYMBOL-MACROLET</B></A> is made to be a special form, aesthetics are improved<P>
|
|
by making symbol macros consistent with normal macros.<P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
A case could be made for adding a new function, SYMBOL-MACRO-FUNCTION, as<P>
|
|
a dual of <A REL=DEFINITION HREF="../Body/f_macro_.htm#macro-function"><B>MACRO-FUNCTION</B></A>. However, symbol macros are simpler than normal<P>
|
|
macros: a symbol macro is associated with a single expansion form, rather<P>
|
|
than an arbitrary function which computes the expansion. For this reason,<P>
|
|
the augmented <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand-1"><B>MACROEXPAND-1</B></A> proposed here can also fill the role of<P>
|
|
SYMBOL-MACRO-FUNCTION: the second value of (macroexpand-1 sym env) will be<P>
|
|
T if and only if sym is a symbol macro, while the first value gives the<P>
|
|
expansion of sym, if it has one.<P>
|
|
<P>
|
|
Rather than extending the existing <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand"><B>MACROEXPAND</B></A> and <A REL=DEFINITION HREF="../Body/f_mexp_.htm#macroexpand-1"><B>MACROEXPAND-1</B></A><P>
|
|
functions, new functions could be introduced to expand symbol macros. <P>
|
|
However, there seems to be no particular reason to do this.<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
----- End Forwarded Messages -----<P>
|
|
</PRE>
|
|
<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>
|