1
0
Fork 0
cl-sites/novaspec.org/cl/f_block.html
2025-02-05 18:52:26 +01:00

341 lines
No EOL
7 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>block | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_block.html"
><LINK REL="next" HREF="f_catch.html" TYPE="text/html" TITLE="catch"
><LINK REL="prev" HREF="f_psetq.html" TYPE="text/html" TITLE="psetq"
><LINK REL="up" HREF="5_3_Data_and_Control_Flow_Dictionary.html" TYPE="text/html" TITLE="5.3 Data and Control Flow 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="5_Data_and_Control_Flow.html"
>5. Data and Control Flow</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="5_3_Data_and_Control_Flow_Dictionary.html"
>5.3 Data and Control Flow Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_block.html"
>block</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_psetq.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_catch.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="block"
></SPAN
><B
>block</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Special</I
> <I
>Operator</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><P CLASS="j"
><B
>block</B
> <VAR CLASS="param"
>name</VAR
> <VAR CLASS="param"
>form</VAR
>* <SPAN CLASS="arrow"
>&#8594;</SPAN
> {<VAR CLASS="param"
>result</VAR
>}*</P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>name</VAR
> &#8212; a <A HREF="26_1_Glossary.html#symbol"
><EM CLASS="term"
>symbol</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>form</VAR
> &#8212; a <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>results</VAR
> &#8212; the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> of the <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>forms</EM
></A
> if a <A HREF="26_1_Glossary.html#normal_return"
><EM CLASS="term"
>normal return</EM
></A
> occurs, or else, if an <A HREF="26_1_Glossary.html#explicit_return"
><EM CLASS="term"
>explicit return</EM
></A
> occurs, the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> that were transferred.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
><A HREF="f_block.html" CLASS="specref"
><B
>block</B
></A
> <A HREF="26_1_Glossary.html#establish"
><EM CLASS="term"
>establishes</EM
></A
> a <A HREF="26_1_Glossary.html#block"
><EM CLASS="term"
>block</EM
></A
> named <VAR CLASS="param"
>name</VAR
> and then evaluates <VAR CLASS="param"
>forms</VAR
> as an <A HREF="26_1_Glossary.html#implicit_progn"
><EM CLASS="term"
>implicit progn</EM
></A
>. </P
><P CLASS="j"
>The <A HREF="26_1_Glossary.html#special_operator"
><EM CLASS="term"
>special operators</EM
></A
> <A HREF="f_block.html" CLASS="specref"
><B
>block</B
></A
> and <A HREF="f_return-from.html" CLASS="specref"
><B
>return-from</B
></A
> work together to provide a structured, lexical, non-local exit facility. At any point lexically contained within <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>forms</EM
></A
>, <A HREF="f_return-from.html" CLASS="specref"
><B
>return-from</B
></A
> can be used with the given <VAR CLASS="param"
>name</VAR
> to return control and values from the <A HREF="f_block.html" CLASS="specref"
><B
>block</B
></A
> <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>, except when an intervening <A HREF="26_1_Glossary.html#block"
><EM CLASS="term"
>block</EM
></A
> with the same name has been <A HREF="26_1_Glossary.html#establish"
><EM CLASS="term"
>established</EM
></A
>, in which case the outer <A HREF="26_1_Glossary.html#block"
><EM CLASS="term"
>block</EM
></A
> is shadowed by the inner one. </P
><P CLASS="j"
>The <A HREF="26_1_Glossary.html#block"
><EM CLASS="term"
>block</EM
></A
> named <A HREF="26_1_Glossary.html#name"
><EM CLASS="term"
>name</EM
></A
> has <A HREF="26_1_Glossary.html#lexical_scope"
><EM CLASS="term"
>lexical scope</EM
></A
> and <A HREF="26_1_Glossary.html#dynamic_extent"
><EM CLASS="term"
>dynamic extent</EM
></A
>. </P
><P CLASS="j"
>Once established, a <A HREF="26_1_Glossary.html#block"
><EM CLASS="term"
>block</EM
></A
> may only be exited once, whether by <A HREF="26_1_Glossary.html#normal_return"
><EM CLASS="term"
>normal return</EM
></A
> or <A HREF="26_1_Glossary.html#explicit_return"
><EM CLASS="term"
>explicit return</EM
></A
>.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
>(block empty) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL
(block whocares (values 1 2) (values 3 4)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 3, 4
(let ((x 1))
(block stop (setq x 2) (return-from stop) (setq x 3))
x) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 2
(block early (return-from early (values 1 2)) (values 3 4)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1, 2
(block outer (block inner (return-from outer 1)) 2) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
(block twin (block twin (return-from twin 1)) 2) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 2
;; Contrast behavior of this example with corresponding example of CATCH.
(block b
(flet ((b1 () (return-from b 1)))
(block b (b1) (print 'unreachable))
2)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1</PRE
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_return.html" CLASS="macref"
><B
>return</B
></A
>, <A HREF="f_return-from.html" CLASS="specref"
><B
>return-from</B
></A
>, <A HREF="3_1_Evaluation.html#sec_3_1" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>3.1</SPAN
> <SPAN CLASS="cmr"
>(Evaluation)</SPAN
></A
></P
></DD
><DT
><B
>Notes</B
></DT
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_psetq.html" CLASS="prev"
>&#8592;</A
><A HREF="f_catch.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
>