153 lines
8.3 KiB
HTML
153 lines
8.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: Issue DOTTED-MACRO-FORMS 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/iss138_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss139.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss140_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/iss138_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss139.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss140_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue DOTTED-MACRO-FORMS Writeup</H2>
|
|
|
|
<PRE><B>Issue:</B> <A HREF="iss139.htm">DOTTED-MACRO-FORMS</A><P>
|
|
<B>References:</B> forms (p54), lists and dotted lists (pp26-27),<P>
|
|
<A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>DEFMACRO</B></A> (p145), destructuring macro arguments (p146)<P>
|
|
<B>Category:</B> CLARIFICATION/CHANGE<P>
|
|
<B>Edit history:</B> 28-Jun-88, Version 1 by Pitman (explicitly-vague vs allow)<P>
|
|
01-Oct-88, Version 2 by Masinter (disallow)<P>
|
|
15-Nov-88, Version 3 by Pitman (revive allow, flush disallow)<P>
|
|
<P>
|
|
<B>Problem Description:<P>
|
|
</B><P>
|
|
CLtL is not explicit about whether macro forms may be dotted<P>
|
|
lists.<P>
|
|
<P>
|
|
p54 says that only certain forms are "meaningful": self-evaluating<P>
|
|
forms, symbols, and "lists".<P>
|
|
<P>
|
|
pp26-27 defines "list" and "dotted list". It goes on to say<P>
|
|
``Throughout this manual, unless otherwise specified, it is an<P>
|
|
error to pass a dotted list to a function that is specified<P>
|
|
to <A REL=DEFINITION HREF="../Body/f_provid.htm#require"><B>require</B></A> a list as an argument.''<P>
|
|
<P>
|
|
p146 states that in <A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>DEFMACRO</B></A> destructuring, ``the argument<P>
|
|
form that would match the parameter is treated as a<P>
|
|
(possibly dotted) list, to be used as an argument forms list<P>
|
|
for satisfying the parameters in the embedded <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> list.''<P>
|
|
It goes on to say that ". var" is treated like "&rest var"<P>
|
|
at any level of the <A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>defmacro</B></A> lambda-list.<P>
|
|
<P>
|
|
<B>Proposal (DOTTED-MACRO-FORMS:ALLOW):<P>
|
|
</B><P>
|
|
Define that it is permissible for a macro form (or subform)<P>
|
|
to be a dotted list when "&REST var" or ". var" is used to match<P>
|
|
it. It is the responsibility of the macro to recognize and deal<P>
|
|
with such situations.<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B> <P>
|
|
Some implementations permit dotted lists in macro forms at toplevel.<P>
|
|
Most or all implementations permit dotted lists in macro forms at<P>
|
|
embedded levels. This proposal makes the language internally<P>
|
|
consistent without requiring changes to existing code.<P>
|
|
<P>
|
|
Also, there's no reason to unnecessarily restrict <A REL=DEFINITION HREF="../Body/03_da.htm#AMrest"><B>&REST</B></A> since there<P>
|
|
is no computational overhead and since there's no dispute about how<P>
|
|
to interpret programmer intent in this gray area.<P>
|
|
<P>
|
|
<B>Test Case:<P>
|
|
</B><P>
|
|
#1: (<A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>DEFMACRO</B></A> MACW (<A REL=DEFINITION HREF="../Body/03_dd.htm#AMwhole"><B>&WHOLE</B></A> W <A REL=DEFINITION HREF="../Body/03_da.htm#AMrest"><B>&REST</B></A> R) `(- ,(<A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>CDR</B></A> W)))<P>
|
|
(MACW . 1) => ??<P>
|
|
<P>
|
|
#2: (<A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>DEFMACRO</B></A> MACR (<A REL=DEFINITION HREF="../Body/03_da.htm#AMrest"><B>&REST</B></A> R) `(- ,R))<P>
|
|
(MACR . 1) => ??<P>
|
|
<P>
|
|
#3: (<A REL=DEFINITION HREF="../Body/m_defmac.htm#defmacro"><B>DEFMACRO</B></A> MACX (<A REL=DEFINITION HREF="../Body/03_dd.htm#AMwhole"><B>&WHOLE</B></A> W) `(- ,(<A REL=DEFINITION HREF="../Body/f_car_c.htm#cdr"><B>CDR</B></A> W)))<P>
|
|
(MACX . 1)<P>
|
|
<P>
|
|
(MACW . 1) => -1 under this proposal.<P>
|
|
(MACR . 1) => -1 under this proposal.<P>
|
|
<P>
|
|
(MACX . 1) is an error under CLtL semantics and is not<P>
|
|
changed by this proposal. The reason it is an<P>
|
|
error is that the argument pattern does not<P>
|
|
match. The pattern is dictated by the arguments<P>
|
|
-other than- the <A REL=DEFINITION HREF="../Body/03_dd.htm#AMwhole"><B>&WHOLE</B></A> argument, so the pattern<P>
|
|
is () and MACX cannot be called with any arguments.<P>
|
|
<P>
|
|
<B>Current Practice:<P>
|
|
</B><P>
|
|
A. Some implementations bind W to (MACW . 1) in #1 and #3<P>
|
|
and bind R to 1 in #1 and #2.<P>
|
|
<P>
|
|
B. Some implementations bind W to (MACW . 1) in #3<P>
|
|
and signal a syntax error in #1 and #2.<P>
|
|
<P>
|
|
C. Some implementations signal a syntax error in #1, #2, and #3.<P>
|
|
Symbolics Genera is such an implementation.<P>
|
|
<P>
|
|
<B>Cost to Implementors:<P>
|
|
</B> <P>
|
|
Some implementations would have to eliminate an error check.<P>
|
|
<P>
|
|
Some implementations which try to use <A REL=DEFINITION HREF="../Body/f_apply.htm#apply"><B>APPLY</B></A> of a normal <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A><P>
|
|
to accomplish part of the destructuring (in the non-recursive case)<P>
|
|
would have to be slightly more careful.<P>
|
|
<P>
|
|
<B>Cost to Users:<P>
|
|
</B> <P>
|
|
None. This change is upward compatible.<P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B><P>
|
|
People would know what to expect.<P>
|
|
<P>
|
|
<B>Aesthetics:<P>
|
|
</B><P>
|
|
Mixed opinion: certainly it is better to specify whether they are<P>
|
|
allowed or an error than to be vague.<P>
|
|
<P>
|
|
Some feel that disallowing dotted macro forms helps catch syntax errors.<P>
|
|
Some feel that allowing dotted macro forms makes the language more regular.<P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
Goldman@VAXA.ISI.EDU raised this issue on Common-Lisp.<P>
|
|
This issue came up primarily in the context of program-written programs;<P>
|
|
a macro used in the program generated code might occasionally use<P>
|
|
a dotted tail to a list to explicitly represent special conditions.<P>
|
|
<P>
|
|
Allowing dotted macro forms may blur the data/code distinction too much, <P>
|
|
particularly for people who are new to Lisp. On the other hand, some people<P>
|
|
argue that the point of macros is to help blur that distinction. Macro<P>
|
|
forms are data which must be translated to program, and only once the<P>
|
|
program claims to be macroexpanded ought syntax restrictions be imposed.<P>
|
|
<P>
|
|
This proposal was rewritten from `DISALLOW' to `ALLOW' after Steele pointed<P>
|
|
out in a recent meeting that dotted lists are allowed in subforms and <P>
|
|
that permitting them at toplevel would be the most internally consistent<P>
|
|
interpretation.<P>
|
|
<P>
|
|
Pitman supports <A HREF="iss139.htm">DOTTED-MACRO-FORMS:ALLOW</A>.<P>
|
|
<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>
|