1
0
Fork 0
cl-sites/novaspec.org/cl/f_dolist.html

468 lines
8.9 KiB
HTML
Raw Normal View History

2025-02-05 18:52:26 +01:00
<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>dolist | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_dolist.html"
><LINK REL="next" HREF="f_loop.html" TYPE="text/html" TITLE="loop"
><LINK REL="prev" HREF="f_dotimes.html" TYPE="text/html" TITLE="dotimes"
><LINK REL="up" HREF="6_2_Iteration_Dictionary.html" TYPE="text/html" TITLE="6.2 Iteration Dictionary"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="6_Iteration.html"
>6. Iteration</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="6_2_Iteration_Dictionary.html"
>6.2 Iteration Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_dolist.html"
>dolist</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_dotimes.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="f_loop.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><DIV CLASS="com"
><DIV CLASS="begincom"
><HR
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="dolist"
></SPAN
><B
>dolist</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Macro</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><DIV CLASS="DefmacWithValuesNewline"
><DIV
><B
>dolist</B
> <SPAN CLASS="cmr"
>(</SPAN
><SPAN CLASS="cmssi"
>var</SPAN
> <SPAN CLASS="cmssi"
>list-form</SPAN
> <SPAN CLASS="cmr"
>[</SPAN
><SPAN CLASS="cmssi"
>result-form</SPAN
><SPAN CLASS="cmr"
>])</SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>declaration</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><SPAN CLASS="cmssi"
>tag</SPAN
> <SPAN CLASS="cmsy"
>|</SPAN
> <SPAN CLASS="cmssi"
>statement</SPAN
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
> </DIV
><DIV
><SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <SPAN CLASS="cmsy"
>{</SPAN
><VAR CLASS="param"
>result</VAR
><SPAN CLASS="cmsy"
>}</SPAN
><SPAN CLASS="cmr"
>*</SPAN
></DIV
></DIV
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>var</VAR
> &#8212; a <A HREF="26_1_Glossary.html#symbol"
><EM CLASS="term"
>symbol</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>list-form</VAR
> &#8212; a <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>result-form</VAR
> &#8212; a <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>declaration</VAR
> &#8212; a <A HREF="m_declare.html" CLASS="misc"
><B
>declare</B
></A
> <A HREF="26_1_Glossary.html#expression"
><EM CLASS="term"
>expression</EM
></A
>; not evaluated. </P
><P CLASS="j"
><VAR CLASS="param"
>tag</VAR
> &#8212; a <A HREF="26_1_Glossary.html#go_tag"
><EM CLASS="term"
>go tag</EM
></A
>; not evaluated. </P
><P CLASS="j"
><VAR CLASS="param"
>statement</VAR
> &#8212; a <A HREF="26_1_Glossary.html#compound_form"
><EM CLASS="term"
>compound form</EM
></A
>; evaluated as described below. </P
><P CLASS="j"
><VAR CLASS="param"
>results</VAR
> &#8212; if a <A HREF="f_return.html" CLASS="macref"
><B
>return</B
></A
> or <A HREF="f_return-from.html" CLASS="specref"
><B
>return-from</B
></A
> form is executed, the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> passed from that <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>; otherwise, the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> returned by the <VAR CLASS="param"
>result-form</VAR
> or <SPAN CLASS="misc"
><B
>nil</B
></SPAN
> if there is no <VAR CLASS="param"
>result-form</VAR
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
><A HREF="f_dolist.html" CLASS="macref"
><B
>dolist</B
></A
> iterates over the elements of a <A HREF="26_1_Glossary.html#list"
><EM CLASS="term"
>list</EM
></A
>. The body of <A HREF="f_dolist.html" CLASS="macref"
><B
>dolist</B
></A
> is like a <A HREF="f_tagbody.html" CLASS="specref"
><B
>tagbody</B
></A
>. It consists of a series of <VAR CLASS="param"
>tags</VAR
> and <VAR CLASS="param"
>statements</VAR
>. </P
><P CLASS="j"
><A HREF="f_dolist.html" CLASS="macref"
><B
>dolist</B
></A
> evaluates <VAR CLASS="param"
>list-form</VAR
>, which should produce a <A HREF="26_1_Glossary.html#list"
><EM CLASS="term"
>list</EM
></A
>. It then executes the body once for each element in the <A HREF="26_1_Glossary.html#list"
><EM CLASS="term"
>list</EM
></A
>, in the order in which the <VAR CLASS="param"
>tags</VAR
> and <VAR CLASS="param"
>statements</VAR
> occur, with <VAR CLASS="param"
>var</VAR
> bound to the element. Then <VAR CLASS="param"
>result-form</VAR
> is evaluated. <VAR CLASS="param"
>tags</VAR
> label <VAR CLASS="param"
>statements</VAR
>. </P
><P CLASS="j"
>At the time <VAR CLASS="param"
>result-form</VAR
> is processed, <VAR CLASS="param"
>var</VAR
> is bound to <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>. </P
><P CLASS="j"
>An <A HREF="26_1_Glossary.html#implicit_block"
><EM CLASS="term"
>implicit block</EM
></A
> named <SPAN CLASS="misc"
><B
>nil</B
></SPAN
> surrounds <A HREF="f_dolist.html" CLASS="macref"
><B
>dolist</B
></A
>. <A HREF="f_return.html" CLASS="macref"
><B
>return</B
></A
> may be used to terminate the loop immediately without performing any further iterations, returning zero or more <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
>. </P
><P CLASS="j"
>The <A HREF="26_1_Glossary.html#scope"
><EM CLASS="term"
>scope</EM
></A
> of the binding of <VAR CLASS="param"
>var</VAR
> does not include the <VAR CLASS="param"
>list-form</VAR
>, but the <VAR CLASS="param"
>result-form</VAR
> is included. </P
><P CLASS="j"
>It is <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
> whether <A HREF="f_dolist.html" CLASS="macref"
><B
>dolist</B
></A
> <A HREF="26_1_Glossary.html#establish"
><EM CLASS="term"
>establishes</EM
></A
> a new <A HREF="26_1_Glossary.html#binding"
><EM CLASS="term"
>binding</EM
></A
> of <VAR CLASS="param"
>var</VAR
> on each iteration or whether it <A HREF="26_1_Glossary.html#establish"
><EM CLASS="term"
>establishes</EM
></A
> a binding for <VAR CLASS="param"
>var</VAR
> once at the beginning and then <VAR CLASS="param"
>assigns</VAR
> it on any subsequent iterations.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (setq temp-two '()) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
(dolist (temp-one '(1 2 3 4) temp-two) (push temp-one temp-two)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (4 3 2 1)
(setq temp-two 0) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 0
(dolist (temp-one '(1 2 3 4)) (incf temp-two)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
temp-two <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 4
(dolist (x '(a b c d)) (prin1 x) (princ " "))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> A B C D
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL</PRE
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_do.html" CLASS="macref"
><B
>do</B
></A
>, <A HREF="f_dotimes.html" CLASS="macref"
><B
>dotimes</B
></A
>, <A HREF="f_tagbody.html" CLASS="specref"
><B
>tagbody</B
></A
>, <A HREF="3_6_Traversal_Rules_and_Side_Effects.html#sec_3_6" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>3.6</SPAN
> <SPAN CLASS="cmr"
>(Traversal</SPAN
> <SPAN CLASS="cmr"
>Rules</SPAN
> <SPAN CLASS="cmr"
>and</SPAN
> <SPAN CLASS="cmr"
>Side</SPAN
> <SPAN CLASS="cmr"
>Effects)</SPAN
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
><A HREF="f_go.html" CLASS="specref"
><B
>go</B
></A
> may be used within the body of <A HREF="f_dolist.html" CLASS="macref"
><B
>dolist</B
></A
> to transfer control to a statement labeled by a <VAR CLASS="param"
>tag</VAR
>.</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_dotimes.html" CLASS="prev"
>&#8592;</A
><A HREF="f_loop.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>