317 lines
7 KiB
HTML
317 lines
7 KiB
HTML
|
<!DOCTYPE HTML>
|
||
|
<HTML LANG="en-us"
|
||
|
><HEAD
|
||
|
><TITLE
|
||
|
>loop-finish | Common Lisp Nova Spec</TITLE
|
||
|
><META CHARSET="US-ASCII"
|
||
|
><LINK REL="canonical" HREF="f_loop-finish.html"
|
||
|
><LINK REL="next" HREF="7_Objects.html" TYPE="text/html" TITLE="7. Objects"
|
||
|
><LINK REL="prev" HREF="f_loop.html" TYPE="text/html" TITLE="loop"
|
||
|
><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"
|
||
|
>→ <A HREF="6_Iteration.html"
|
||
|
>6. Iteration</A
|
||
|
></SPAN
|
||
|
> <SPAN CLASS="breadcrumb-item"
|
||
|
>→ <A HREF="6_2_Iteration_Dictionary.html"
|
||
|
>6.2 Iteration Dictionary</A
|
||
|
></SPAN
|
||
|
> <SPAN CLASS="breadcrumb-item"
|
||
|
>→ <A HREF="f_loop-finish.html"
|
||
|
>loop-finish</A
|
||
|
></SPAN
|
||
|
></DIV
|
||
|
><DIV CLASS="apropos"
|
||
|
><DIV CLASS="apropos-io"
|
||
|
><A HREF="f_loop.html" CLASS="prev"
|
||
|
>←</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="7_Objects.html" CLASS="next"
|
||
|
>→</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="loop-finish"
|
||
|
></SPAN
|
||
|
><B
|
||
|
>loop-finish</B
|
||
|
></TD
|
||
|
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
|
||
|
><I
|
||
|
>Local</I
|
||
|
> <I
|
||
|
>Macro</I
|
||
|
></TD
|
||
|
></TR
|
||
|
></TABLE
|
||
|
><HR
|
||
|
></DIV
|
||
|
><UL CLASS="subtoc"
|
||
|
></UL
|
||
|
><DL
|
||
|
><DT
|
||
|
><B
|
||
|
>Syntax</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
><B
|
||
|
>loop-finish</B
|
||
|
> ⟨<I
|
||
|
>no</I
|
||
|
> <A HREF="26_1_Glossary.html#argument"
|
||
|
><EM CLASS="term"
|
||
|
>arguments</EM
|
||
|
></A
|
||
|
>⟩ <SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
>|</P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Description</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
>The <A HREF="f_loop-finish.html" CLASS="macref"
|
||
|
><B
|
||
|
>loop-finish</B
|
||
|
></A
|
||
|
> <A HREF="26_1_Glossary.html#macro"
|
||
|
><EM CLASS="term"
|
||
|
>macro</EM
|
||
|
></A
|
||
|
> can be used lexically within an extended <A HREF="f_loop.html" CLASS="macref"
|
||
|
><B
|
||
|
>loop</B
|
||
|
></A
|
||
|
> <A HREF="26_1_Glossary.html#form"
|
||
|
><EM CLASS="term"
|
||
|
>form</EM
|
||
|
></A
|
||
|
> to terminate that <A HREF="26_1_Glossary.html#form"
|
||
|
><EM CLASS="term"
|
||
|
>form</EM
|
||
|
></A
|
||
|
> “normally.” That is, it transfers control to the loop epilogue of the lexically innermost extended <A HREF="f_loop.html" CLASS="macref"
|
||
|
><B
|
||
|
>loop</B
|
||
|
></A
|
||
|
> <A HREF="26_1_Glossary.html#form"
|
||
|
><EM CLASS="term"
|
||
|
>form</EM
|
||
|
></A
|
||
|
>. This permits execution of any <SPAN CLASS="macref"
|
||
|
><B
|
||
|
>finally</B
|
||
|
></SPAN
|
||
|
> clause (for effect) and the return of any accumulated result.</P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Examples</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><PRE CLASS="screen"
|
||
|
>;; Terminate the loop, but return the accumulated count.
|
||
|
(loop for i in '(1 2 3 stop-here 4 5 6)
|
||
|
when (symbolp i) do (loop-finish)
|
||
|
count i)
|
||
|
<SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 3
|
||
|
|
||
|
;; The preceding loop is equivalent to:
|
||
|
(loop for i in '(1 2 3 stop-here 4 5 6)
|
||
|
until (symbolp i)
|
||
|
count i)
|
||
|
<SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 3
|
||
|
|
||
|
;; While LOOP-FINISH can be used can be used in a variety of
|
||
|
;; situations it is really most needed in a situation where a need
|
||
|
;; to exit is detected at other than the loop's `top level'
|
||
|
;; (where UNTIL or WHEN often work just as well), or where some
|
||
|
;; computation must occur between the point where a need to exit is
|
||
|
;; detected and the point where the exit actually occurs. For example:
|
||
|
(defun tokenize-sentence (string)
|
||
|
(macrolet ((add-word (wvar svar)
|
||
|
`(when ,wvar
|
||
|
(push (coerce (nreverse ,wvar) 'string) ,svar)
|
||
|
(setq ,wvar nil))))
|
||
|
(loop with word = '() and sentence = '() and endpos = nil
|
||
|
for i below (length string)
|
||
|
do (let ((char (aref string i)))
|
||
|
(case char
|
||
|
(#\Space (add-word word sentence))
|
||
|
(#\. (setq endpos (1+ i)) (loop-finish))
|
||
|
(otherwise (push char word))))
|
||
|
finally (add-word word sentence)
|
||
|
(return (values (nreverse sentence) endpos)))))
|
||
|
<SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> TOKENIZE-SENTENCE
|
||
|
|
||
|
(tokenize-sentence "this is a sentence. this is another sentence.")
|
||
|
<SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> ("this" "is" "a" "sentence"), 19
|
||
|
|
||
|
(tokenize-sentence "this is a sentence")
|
||
|
<SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> ("this" "is" "a" "sentence"), NIL</PRE
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Side Effects</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
>Transfers control.</P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Exceptional Situations</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
>Whether or not <A HREF="f_loop-finish.html" CLASS="macref"
|
||
|
><B
|
||
|
>loop-finish</B
|
||
|
></A
|
||
|
> is <A HREF="26_1_Glossary.html#fbound"
|
||
|
><EM CLASS="term"
|
||
|
>fbound</EM
|
||
|
></A
|
||
|
> in the <A HREF="26_1_Glossary.html#global_environment"
|
||
|
><EM CLASS="term"
|
||
|
>global environment</EM
|
||
|
></A
|
||
|
> is <A HREF="26_1_Glossary.html#implementation-dependent"
|
||
|
><EM CLASS="term"
|
||
|
>implementation-dependent</EM
|
||
|
></A
|
||
|
>; however, the restrictions on redefinition and <A HREF="26_1_Glossary.html#shadow"
|
||
|
><EM CLASS="term"
|
||
|
>shadowing</EM
|
||
|
></A
|
||
|
> of <A HREF="f_loop-finish.html" CLASS="macref"
|
||
|
><B
|
||
|
>loop-finish</B
|
||
|
></A
|
||
|
> are the same as for <A HREF="26_1_Glossary.html#symbol"
|
||
|
><EM CLASS="term"
|
||
|
>symbols</EM
|
||
|
></A
|
||
|
> in the <SPAN CLASS="packref"
|
||
|
><SPAN CLASS="cmtt"
|
||
|
>COMMON-LISP</SPAN
|
||
|
></SPAN
|
||
|
> <A HREF="26_1_Glossary.html#package"
|
||
|
><EM CLASS="term"
|
||
|
>package</EM
|
||
|
></A
|
||
|
> which are <A HREF="26_1_Glossary.html#fbound"
|
||
|
><EM CLASS="term"
|
||
|
>fbound</EM
|
||
|
></A
|
||
|
> in the <A HREF="26_1_Glossary.html#global_environment"
|
||
|
><EM CLASS="term"
|
||
|
>global environment</EM
|
||
|
></A
|
||
|
>. The consequences of attempting to use <A HREF="f_loop-finish.html" CLASS="macref"
|
||
|
><B
|
||
|
>loop-finish</B
|
||
|
></A
|
||
|
> outside of <A HREF="f_loop.html" CLASS="macref"
|
||
|
><B
|
||
|
>loop</B
|
||
|
></A
|
||
|
> are undefined.</P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>See Also</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
><A HREF="f_loop.html" CLASS="macref"
|
||
|
><B
|
||
|
>loop</B
|
||
|
></A
|
||
|
>, <A HREF="6_1_The_LOOP_Facility.html#sec_6_1" CLASS="secref"
|
||
|
><SPAN CLASS="cmr"
|
||
|
>Section</SPAN
|
||
|
> <SPAN CLASS="cmr"
|
||
|
>6.1</SPAN
|
||
|
> <SPAN CLASS="cmr"
|
||
|
>(The</SPAN
|
||
|
> <SPAN CLASS="cmr"
|
||
|
>LOOP</SPAN
|
||
|
> <SPAN CLASS="cmr"
|
||
|
>Facility)</SPAN
|
||
|
></A
|
||
|
></P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Notes</B
|
||
|
></DT
|
||
|
></DL
|
||
|
></DIV
|
||
|
></DIV
|
||
|
><DIV CLASS="footer"
|
||
|
><DIV CLASS="btmnav"
|
||
|
><A HREF="f_loop.html" CLASS="prev"
|
||
|
>←</A
|
||
|
><A HREF="7_Objects.html" CLASS="next"
|
||
|
>→</A
|
||
|
></DIV
|
||
|
><DIV CLASS="trail"
|
||
|
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
|
||
|
></DIV
|
||
|
></DIV
|
||
|
><SCRIPT
|
||
|
>domReady();</SCRIPT
|
||
|
></BODY
|
||
|
></HTML
|
||
|
>
|