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

330 lines
16 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 LOOP-SYNTAX-OVERHAUL 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/iss225_w.htm">
<LINK REL=UP HREF="../Issues/iss226.htm">
<LINK REL=NEXT HREF="../Issues/iss227_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/iss225_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss226.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss227_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue LOOP-SYNTAX-OVERHAUL Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss226.htm">LOOP-SYNTAX-OVERHAUL</A><P>
<B>Forum:</B> X3J13 Letter Ballot<P>
<B>References:</B> <A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>LOOP</B></A> syntax (X3J13/92-102 pp6-2..6-5)<P>
<B>Category:</B> CLARIFICATION<P>
<B>Edit history:</B> 16-Jun-93, Version 1 by Pitman<P>
<B>Status:</B> Proposal REPAIR passed (7+3)-1 on letter ballot 93-304.<P>
<P>
<P>
<B>Problem Description:<P>
</B><P>
The <A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>LOOP</B></A> syntax in the first dpANS all screwed up.<P>
<P>
<B>Proposal (LOOP-SYNTAX-OVERHAUL:REPAIR):<P>
</B><P>
Affirm that the following changes to the source relating to <A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>LOOP</B></A> syntax<P>
are in fact editorial and that nothing has been broken. Note that several<P>
recently passed cleanups are implicitly included in this writeup.<P>
<P>
A typeset version of this code should have been attached for the reader's<P>
convenience, but the TeX source code is what is being voted upon and kept <P>
as a record. This requires a new TeX macro library, not included.<P>
<P>
Note that two new notations are used to make this work:<P>
[[ { x }1 | { y }* ]]<P>
means that x can occur anywhere, but exactly once (it is not optional).<P>
And <P>
[[ x | y | ... ]]+<P>
means that at least one of the enclosed options must be selected.<P>
(Appropriate text has been added to Section 1.4 to explain this new<P>
notational extension.)<P>
<P>
\input setup % -*- Mode: TeX -*-<P>
<P>
\beginchapter{X}{LOOP}{ChapX}{LOOP}<P>
<P>
%%% ========== <A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>LOOP</B></A><P>
\begincom{loop}\ftype{Macro}<P>
<P>
\label Syntax::<P>
<P>
The ``simple'' \macref{loop} \term{form}:<P>
<P>
\DefmacWithValues loop {\starparam{compound-form}} {\starparam{result}}<P>
<P>
The ``extended'' \macref{loop} \term{form}:<P>
<P>
\DefmacWithValues loop {\brac{\down{name-clause}}<P>
\stardown{variable-clause}<P>
\stardown{main-clause}} {\starparam{result}}<P>
<P>
\auxbnf{name-clause}{\loopref{named} \param{name}}<P>
\auxbnf{variable-clause}{\down{with-clause} | \down{initial-final} | \down{for-as-clause}}<P>
\auxbnf{with-clause}%<P>
{\loopref{with} \param{var1} \brac{\param{type-spec}} \brac{$=$ \param{form1}}<P>
\star{\curly{\loopref{and} \param{var2} \brac{\param{type-spec}} <P>
\brac{$=$ \param{form2}}}}}<P>
\auxbnf{main-clause}%<P>
{\down{unconditional} |<P>
\down{accumulation} |<P>
\down{conditional} |<P>
\down{end-test} |<P>
\down{initial-final}}<P>
\auxbnf{initial-final}%<P>
{\loopref{initially} \plusparam{form} | \loopref{finally} \plusparam{form}}<P>
\auxbnf{unconditional}%<P>
{\curly{\loopref{do} | \loopref{doing}} \plusparam{form} |<P>
\loopref{return} \param{form}}<P>
\auxbnf{accumulation}{\down{list-accumulation} | \down{numeric-accumulation}}<P>
\auxbnf{list-accumulation}%<P>
{\curly{\loopref{collect} | \loopref{collecting} |<P>
\loopref{append} | \loopref{appending} |<P>
\loopref{nconc} | \loopref{nconcing}} \param{form} \CR<P>
\brac{\loopref{into} \param{var}}}<P>
\auxbnf{numeric-accumulation}%<P>
{\curly{\loopref{count} | \loopref{counting} |<P>
\loopref{sum} | \loopref{summing} | \CR<P>
\xcurly\loopref{maximize} | \loopref{maximizing} |<P>
\loopref{minimize} | \loopref{minimizing}} \param{form} \CR<P>
\brac{\loopref{into} \param{var}} \brac{\param{type-spec}}}<P>
\auxbnf{conditional}%<P>
{\curly{\loopref{if} | \loopref{when} | \loopref{unless}} \param{form}<P>
\param{selectable-clause} \star{\curly{\loopref{and} \param{selectable-clause}}} \CR<P>
\brac{\loopref{else}<P>
\param{selectable-clause} \star{\curly{\loopref{and} \param{selectable-clause}}}} \CR<P>
\brac{\loopref{end}}}<P>
%% I flushed the clause/clause1/clause2 distinction in the next thing, since it's not used<P>
%% anywhere for reference, and it's not appropriate to the bnf style.<P>
%% However, I'm concerned about the loss of IT here due to <A HREF="iss223.htm">LOOP-MISCELLANEOUS-REPAIRS</A>.<P>
%% -kmp 4-May-93<P>
\auxbnf{selectable-clause}{\down{unconditional} | \down{accumulation} | \down{conditional}}<P>
\auxbnf{end-test}%<P>
{\loopref{while} \param{form} | <P>
\loopref{until} \param{form} |<P>
\loopref{repeat} \param{form} |<P>
\loopref{always} \param{form} |<P>
\loopref{never} \param{form} |<P>
\loopref{thereis} \param{form}}<P>
\auxbnf{for-as-clause}%<P>
{\curly{\loopref{for} | \loopref{as}} \down{for-as-subclause}<P>
\star{\curly{\loopref{and} \down{for-as-subclause}}}}<P>
\auxbnf{for-as-subclause}%<P>
{\down{for-as-arithmetic} |<P>
\down{for-as-in-list} |<P>
\down{for-as-on-list} |<P>
\down{for-as-equals-then} |\CR<P>
\down{for-as-across} |<P>
\down{for-as-hash} |<P>
\down{for-as-package}}<P>
\auxbnf{for-as-arithmetic}{\param{var} \brac{\param{type-spec}}<P>
\down{for-as-arithmetic-subclause}}<P>
\auxbnf{for-as-arithmetic-subclause}%<P>
{\down{arithmetic-up} | \down{arithmetic-downto} | \down{arithmetic-downfrom}}<P>
\auxbnf{arithmetic-up}%<P>
{\begininterleave\curly{\loopref{from} | \loopref{upfrom}} \param{form1} | <P>
\extrainterleave\curly{\loopref{to} | \loopref{upto} | \loopref{below}} \param{form2} | <P>
\extrainterleave\loopref{by} \param{form3}\endinterleave\prevplus}<P>
\auxbnf{arithmetic-downto}%<P>
{\begininterleave\one{\curly{\loopref{from} \param{form1}}} | <P>
\extrainterleave\one{\curly{\curly{\loopref{downto} | \loopref{above}} \param{form2}}} | <P>
\extrainterleave\loopref{by} \param{form3}\endinterleave}<P>
\auxbnf{arithmetic-downfrom}%<P>
{\begininterleave\one{\curly{\loopref{downfrom} \param{form1}}} | <P>
\extrainterleave\curly{\loopref{to} | \loopref{downto} | \loopref{above}} \param{form2} | <P>
\extrainterleave\loopref{by} \param{form3}\endinterleave}<P>
\auxbnf{for-as-in-list}%<P>
{\param{var} \brac{\param{type-spec}}<P>
\loopref{in} \param{form1} \brac{\loopref{by} \param{step-fun}}}<P>
\auxbnf{for-as-on-list}%<P>
{\param{var} \brac{\param{type-spec}}<P>
\loopref{on} \param{form1} \brac{\loopref{by} \param{step-fun}}}<P>
\auxbnf{for-as-equals-then}%<P>
{\param{var} \brac{\param{type-spec}}<P>
$=$ \param{form1} \brac{\loopref{then} \param{form2}}}<P>
\auxbnf{for-as-across}%<P>
{\param{var} \brac{\param{type-spec}}<P>
\loopref{across} \param{vector}}<P>
\auxbnf{for-as-hash}%<P>
{\param{var} \brac{\param{type-spec}}<P>
\loopref{being} \curly{\loopref{each} | \loopref{the}} \CR<P>
\lcurly\curly{\loopref{hash-key} | \loopref{hash-keys}}<P>
\curly{\loopref{in} | \loopref{of}} \param{hash-table} \CR<P>
\xcurly\brac{\loopref{using} \paren{\loopref{hash-value} \param{other-var}}} | \CR<P>
\xcurly\curly{\loopref{hash-value} | \loopref{hash-values}}<P>
\curly{\loopref{in} | \loopref{of}} \param{hash-table} \CR<P>
\xcurly\brac{\loopref{using} \paren{\loopref{hash-key} \param{other-var}}}\rcurly}<P>
\auxbnf{for-as-package}%<P>
{\param{var} \brac{\param{type-spec}}<P>
\loopref{being} \curly{\loopref{each} | \loopref{the}} \CR<P>
\lcurly\loopref{symbol} | \loopref{symbols} |\CR<P>
\xcurly\loopref{present-symbol} | \loopref{present-symbols} |\CR<P>
\xcurly\loopref{external-symbol} | \loopref{external-symbols}\rcurly \CR<P>
\brac{\curly{\loopref{in} | \loopref{of}} \param{package}}}<P>
\auxbnf{type-spec}{\down{simple-type-spec} | \down{destructured-type-spec}}<P>
\auxbnf{simple-type-spec}%<P>
{\declref{fixnum} | \declref{float} | \declref{t} | \declref{nil}}<P>
\auxbnf{destructured-type-spec}{\loopref{of-type} \param{d-type-spec}}<P>
\auxbnf{d-type-spec}%<P>
{\param{type-specifier} | \f{(\param{d-type-spec} . \param{d-type-spec})}}<P>
<P>
\label Arguments and Values::<P>
<P>
\param{compound-form}---a \term{compound form}.<P>
<P>
\param{name}---a \term{symbol}.<P>
<P>
\param{var}, \param{var1}, \param{var2}, \param{other-var}---a \term{symbol}<P>
(a \term{variable} \term{name}).<P>
<P>
\param{form}, \param{form1}, \param{form2}, \param{form3}---a \term{form}.<P>
<P>
\issue{LOOP-MISCELLANEOUS-REPAIRS:FIX}<P>
\param{step-fun}---a \term{form} that evaluates to a \term{function} of one \term{argument}.<P>
\endissue{LOOP-MISCELLANEOUS-REPAIRS:FIX}<P>
<P>
\param{vector}---a \term{form} that evaluates to a \term{vector}.<P>
<P>
\param{hash-table}---a \term{form} that evaluates to a \term{hash table}.<P>
<P>
\param{package}---a \term{form} that evaluates to a \term{package designator}.<P>
<P>
\param{type-specifier}---a \term{type specifier}.<P>
<P>
\param{result}---an \term{object}.<P>
<P>
\label Description::<P>
<P>
%!!! This should be elaborated slightly here.<P>
For details, \seesection\LoopFacility.<P>
<P>
\label Examples::<P>
<P>
\code<P>
;; An example of the simple form of <A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>LOOP</B></A>.<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>defun</B></A> sqrt-advisor ()<P>
(<A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>loop</B></A> (<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>format</B></A> t &quot;~&amp;Number: &quot;)<P>
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>let</B></A> ((n (<A REL=DEFINITION HREF="../Body/f_parse_.htm#parse-integer"><B>parse-integer</B></A> (<A REL=DEFINITION HREF="../Body/f_rd_lin.htm#read-line"><B>read-line</B></A>) :junk-allowed t)))<P>
(<A REL=DEFINITION HREF="../Body/m_when_.htm#when"><B>when</B></A> (<A REL=DEFINITION HREF="../Body/a_not.htm#not"><B>not</B></A> n) (<A REL=DEFINITION HREF="../Body/m_return.htm#return"><B>return</B></A>))<P>
(<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>format</B></A> t &quot;~&amp;The square root of ~D is ~D.~%&quot; n (<A REL=DEFINITION HREF="../Body/f_sqrt_.htm#sqrt"><B>sqrt</B></A> n)))))<P>
\EV SQRT-ADVISOR<P>
(sqrt-advisor)<P>
\OUT Number: \IN{5\CRLF}<P>
\OUT The square root of 5 is 2.236068.<P>
\OUT Number: \IN{4\CRLF}<P>
\OUT The square root of 4 is 2.<P>
\OUT Number: \IN{done\CRLF}<P>
\EV <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A><P>
<P>
;; An example of the extended form of <A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>LOOP</B></A>.<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>defun</B></A> square-advisor ()<P>
(<A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>loop</B></A> as n = (<A REL=DEFINITION HREF="../Body/s_progn.htm#progn"><B>progn</B></A> (<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>format</B></A> t &quot;~&amp;Number: &quot;)<P>
(<A REL=DEFINITION HREF="../Body/f_parse_.htm#parse-integer"><B>parse-integer</B></A> (<A REL=DEFINITION HREF="../Body/f_rd_lin.htm#read-line"><B>read-line</B></A>) :junk-allowed t))<P>
while n<P>
<A REL=DEFINITION HREF="../Body/m_do_do.htm#do"><B>do</B></A> (<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>format</B></A> t &quot;~&amp;The square of ~D is ~D.~%&quot; n (* n n))))<P>
\EV SQUARE-ADVISOR<P>
(square-advisor)<P>
\OUT Number: \IN{4\CRLF}<P>
\OUT The square of 4 is 16.<P>
\OUT Number: \IN{23\CRLF}<P>
\OUT The square of 23 is 529.<P>
\OUT Number: \IN{done\CRLF}<P>
\EV <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A><P>
<P>
;; Another example of the extended form of <A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>LOOP</B></A>.<P>
(<A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>loop</B></A> for n from 1 to 10<P>
<A REL=DEFINITION HREF="../Body/m_when_.htm#when"><B>when</B></A> (<A REL=DEFINITION HREF="../Body/f_evenpc.htm#oddp"><B>oddp</B></A> n)<P>
collect n)<P>
\EV (1 3 5 7 9)<P>
\endcode<P>
<P>
\label Affected By:\None.<P>
<P>
\label Exceptional Situations:\None.<P>
<P>
%!!! Barmar: The description mentions several places where <A REL=DEFINITION HREF="../Body/e_progra.htm#program-error"><B>PROGRAM-ERROR</B></A> is signaled.<P>
<P>
\label See Also::<P>
<P>
\macref{do}, \macref{dolist}, \macref{dotimes}, <P>
\macref{return}, \specref{go}, \specref{throw}<P>
<P>
\label Notes::<P>
<P>
The simple form of \macref{loop} is related to the extended form<P>
in the following way:<P>
<P>
\code<P>
(loop \starparam{compound-form}) \EQ (loop do \starparam{compound-form})<P>
\endcode<P>
<P>
\endcom%{loop}<P>
<P>
\endchapter<P>
<P>
\bye<P>
<P>
<B>Test Case:<P>
</B><P>
N/A<P>
<P>
<B>Rationale:<P>
</B><P>
What was there was utterly broken, so how could we do worse?<P>
<P>
<B>Current Practice:<P>
</B><P>
N/A<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Hopefully very small. This is not really supposed to be a change, <P>
just a clarification for readability.<P>
<P>
<B>Cost to Users:<P>
</B><P>
Hopefully very small. This is not really supposed to be a change, <P>
just a clarification for readability.<P>
<P>
<B>Cost of Non-Adoption:<P>
</B><P>
A hopelessly messed up description of <A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>LOOP</B></A>'s syntax.<P>
<P>
<B>Benefits:<P>
</B><P>
Using <A REL=DEFINITION HREF="../Body/m_loop.htm#loop"><B>LOOP</B></A> just from the documentation will be possible.<P>
<P>
<B>Editorial Impact:<P>
</B><P>
This affirms work already done.<P>
<P>
<B>Aesthetics:<P>
</B><P>
What was there was so broken that this is unquestionably an improvement.<P>
<P>
<B>Discussion:<P>
</B><P>
Pitman thinks this is just a rubber stamp, and that only editorial changes<P>
have been made here. He just wanted the committee to have a chance to <P>
double-check this work specially.<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>