40 lines
7 KiB
HTML
40 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: Section 6.1.1.4</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="06_aac.htm">
|
|
<LINK REL=UP HREF="06_aa.htm">
|
|
<LINK REL=NEXT HREF="06_aae.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="06_aac.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="06_aa.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="06_aae.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<H2>
|
|
6.1.1.4 Expanding Loop Forms</H2> <P>
|
|
A <A REL=DEFINITION HREF="m_loop.htm#loop"><B>loop</B></A> <A REL=DEFINITION HREF="26_glo_m.htm#macro_form"><I>macro form</I></A> expands into a <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> containing one or more binding forms (that <A REL=DEFINITION HREF="26_glo_e.htm#establish"><I>establish</I></A> <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>bindings</I></A> of loop variables) and a <A REL=DEFINITION HREF="s_block.htm#block"><B>block</B></A> and a <A REL=DEFINITION HREF="s_tagbod.htm#tagbody"><B>tagbody</B></A> (that express a looping control structure). The variables established in <A REL=DEFINITION HREF="m_loop.htm#loop"><B>loop</B></A> are bound as if by <A REL=DEFINITION HREF="s_let_l.htm#let"><B>let</B></A> or <A REL=DEFINITION HREF="a_lambda.htm#lambda"><B>lambda</B></A>. <P>
|
|
Implementations can interleave the setting of initial values with the <A REL=DEFINITION HREF="26_glo_b.htm#binding"><I>bindings</I></A>. However, the assignment of the initial values is always calculated in the order specified by the user. A variable is thus sometimes bound to a meaningless value of the correct <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A>, and then later in the prologue it is set to the true initial value by using <A REL=DEFINITION HREF="s_setq.htm#setq"><B>setq</B></A>. One implication of this interleaving is that it is <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A> whether the <A REL=DEFINITION HREF="26_glo_l.htm#lexical_environment"><I>lexical environment</I></A> in which the initial value <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> (variously called the <I>form1</I>, <I>form2</I>, <I>form3</I>, <I>step-fun</I>, <I>vector</I>, <I>hash-table</I>, and <I>package</I>) in any <I>for-as-subclause</I>, except <I>for-as-equals-then</I>, are <I>evaluated</I> includes only the loop variables preceding that <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> or includes more or all of the loop variables; the <I>form1</I> and <I>form2</I> in a <I>for-as-equals-then</I> form includes the <A REL=DEFINITION HREF="26_glo_l.htm#lexical_environment"><I>lexical environment</I></A> of all the loop variables. <P>
|
|
After the <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> is expanded, it consists of three basic parts in the <A REL=DEFINITION HREF="s_tagbod.htm#tagbody"><B>tagbody</B></A>: the loop prologue, the loop body, and the loop epilogue. <P>
|
|
<P><DL><DT><B>Loop prologue</B> <P><DD>
|
|
The loop prologue contains <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> that are executed before iteration begins, such as any automatic variable initializations prescribed by the <I>variable</I> clauses, along with any <TT>initially</TT> clauses in the order they appear in the source. <P>
|
|
<DT><B>Loop body</B> <P><DD>
|
|
The loop body contains those <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> that are executed during iteration, including application-specific calculations, termination tests, and variable <I>stepping</I>[1]. <P>
|
|
<DT><B>Loop epilogue</B> <P><DD>
|
|
The loop epilogue contains <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> that are executed after iteration terminates, such as <TT>finally</TT> clauses, if any, along with any implicit return value from an <I>accumulation</I> clause or an <I>termination-test</I> clause. <P>
|
|
<P></DL><P>
|
|
Some clauses from the source <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> contribute code only to the loop prologue; these clauses must come before other clauses that are in the main body of the <A REL=DEFINITION HREF="m_loop.htm#loop"><B>loop</B></A> form. Others contribute code only to the loop epilogue. All other clauses contribute to the final translated <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> in the same order given in the original source <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> of the <A REL=DEFINITION HREF="m_loop.htm#loop"><B>loop</B></A>. <P>
|
|
Expansion of the <A REL=DEFINITION HREF="m_loop.htm#loop"><B>loop</B></A> macro produces an <A REL=DEFINITION HREF="26_glo_i.htm#implicit_block"><I>implicit block</I></A> named <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A> unless <TT>named</TT> is supplied. Thus, <A REL=DEFINITION HREF="s_ret_fr.htm#return-from"><B>return-from</B></A> (and sometimes <A REL=DEFINITION HREF="m_return.htm#return"><B>return</B></A>) can be used to return values from <A REL=DEFINITION HREF="m_loop.htm#loop"><B>loop</B></A> or to exit <A REL=DEFINITION HREF="m_loop.htm#loop"><B>loop</B></A>. <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/iss224.htm">LOOP-NAMED-BLOCK-NIL:OVERRIDE</A><LI> <A REL=CHILD HREF="../Issues/iss222.htm">LOOP-INITFORM-ENVIRONMENT:PARTIAL-INTERLEAVING-VAGUE</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>
|