Debian Codegraph @

info/gcl/block.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>block (ANSI and GNU Common Lisp Document)</title>
7
8 <meta name="description" content="block (ANSI and GNU Common Lisp Document)">
9 <meta name="keywords" content="block (ANSI and GNU Common Lisp Document)">
10 <meta name="resource-type" content="document">
11 <meta name="distribution" content="global">
12 <meta name="Generator" content="makeinfo">
13 <link href="index.html" rel="start" title="Top">
14 <link href="Data-and-Control-Flow-Dictionary.html" rel="up" title="Data and Control Flow Dictionary">
15 <link href="catch.html" rel="next" title="catch">
16 <link href="psetq.html" rel="prev" title="psetq">
17 <style type="text/css">
18 <!--
19 a.summary-letter {text-decoration: none}
20 blockquote.indentedblock {margin-right: 0em}
21 div.display {margin-left: 3.2em}
22 div.example {margin-left: 3.2em}
23 div.lisp {margin-left: 3.2em}
24 kbd {font-style: oblique}
25 pre.display {font-family: inherit}
26 pre.format {font-family: inherit}
27 pre.menu-comment {font-family: serif}
28 pre.menu-preformatted {font-family: serif}
29 span.nolinebreak {white-space: nowrap}
30 span.roman {font-family: initial; font-weight: normal}
31 span.sansserif {font-family: sans-serif; font-weight: normal}
32 ul.no-bullet {list-style: none}
33 -->
34 </style>
35
36
37 </head>
38
39 <body lang="en">
40 <span id="block"></span><div class="header">
41 <p>
42 Next: <a href="catch.html" accesskey="n" rel="next">catch</a>, Previous: <a href="psetq.html" accesskey="p" rel="prev">psetq</a>, Up: <a href="Data-and-Control-Flow-Dictionary.html" accesskey="u" rel="up">Data and Control Flow Dictionary</a> &nbsp; </p>
43 </div>
44 <hr>
45 <span id="block-_005bSpecial-Operator_005d"></span><h4 class="subsection">5.3.22 block [Special Operator]</h4>
46
47 <p><code>block</code> <i><i>name</i> <i>form</i><span class="roman">*</span></i> &rArr; <i>{<i>result</i>}*</i>
48 </p>
49 <span id="Arguments-and-Values_003a_003a-43"></span><h4 class="subsubheading">Arguments and Values::</h4>
50
51 <p><i>name</i>&mdash;a <i>symbol</i>.
52 </p>
53 <p><i>form</i>&mdash;a <i>form</i>.
54 </p>
55 <p><i>results</i>&mdash;the <i>values</i> of the <i>forms</i> if a <i>normal return</i> occurs,
56 or else, if an <i>explicit return</i> occurs, the <i>values</i> that were transferred.
57 </p>
58 <span id="Description_003a_003a-75"></span><h4 class="subsubheading">Description::</h4>
59
60 <p><b>block</b> <i>establishes</i> a <i>block</i> named <i>name</i>
61 and then evaluates <i>forms</i> as an <i>implicit progn</i>.
62 </p>
63 <p>The <i>special operators</i> <b>block</b> and <b>return-from</b> work together to
64 provide a structured, lexical, non-local exit facility. At any point lexically
65 contained within <i>forms</i>, <b>return-from</b> can be used with the
66 given <i>name</i> to return control and values from the <b>block</b>
67 <i>form</i>, except when an intervening <i>block</i> with the same name
68 has been <i>established</i>, in which case the outer <i>block</i> is
69 shadowed by the inner one.
70 </p>
71 <p>The <i>block</i> named <i>name</i> has
72 <i>lexical scope</i> and <i>dynamic extent</i>.
73 </p>
74 <p>Once established, a <i>block</i> may only be exited once,
75 whether by <i>normal return</i> or <i>explicit return</i>.
76 </p>
77 <span id="Examples_003a_003a-49"></span><h4 class="subsubheading">Examples::</h4>
78
79 <div class="example">
80 <pre class="example"> (block empty) &rArr; NIL
81 (block whocares (values 1 2) (values 3 4)) &rArr; 3, 4
82 (let ((x 1))
83 (block stop (setq x 2) (return-from stop) (setq x 3))
84 x) &rArr; 2
85 (block early (return-from early (values 1 2)) (values 3 4)) &rArr; 1, 2
86 (block outer (block inner (return-from outer 1)) 2) &rArr; 1
87 (block twin (block twin (return-from twin 1)) 2) &rArr; 2
88 ;; Contrast behavior of this example with corresponding example of CATCH.
89 (block b
90 (flet ((b1 () (return-from b 1)))
91 (block b (b1) (print 'unreachable))
92 2)) &rArr; 1
93 </pre></div>
94
95 <span id="See-Also_003a_003a-60"></span><h4 class="subsubheading">See Also::</h4>
96
97 <p><a href="return.html">return</a>
98 ,
99 <a href="return_002dfrom.html">return-from</a>
100 , <a href="Evaluation.html">Evaluation</a>
101 </p>
102 <span id="Notes_003a_003a-36"></span><h4 class="subsubheading">Notes::</h4>
103
104
105
106
107 </body>
108 </html>