Debian Codegraph @

info/gcl/abort-_0028Function_0029.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>abort (Function) (ANSI and GNU Common Lisp Document)</title>
7
8 <meta name="description" content="abort (Function) (ANSI and GNU Common Lisp Document)">
9 <meta name="keywords" content="abort (Function) (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="Conditions-Dictionary.html" rel="up" title="Conditions Dictionary">
15 <link href="Symbols.html" rel="next" title="Symbols">
16 <link href="use_002dvalue.html" rel="prev" title="use-value">
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="abort-_0028Function_0029"></span><div class="header">
41 <p>
42 Previous: <a href="use_002dvalue.html" accesskey="p" rel="prev">use-value</a>, Up: <a href="Conditions-Dictionary.html" accesskey="u" rel="up">Conditions Dictionary</a> &nbsp; </p>
43 </div>
44 <hr>
45 <span id="abort_002c-continue_002c-muffle_002dwarning_002c-store_002dvalue_002c-use_002dvalue-_005bFunction_005d"></span><h4 class="subsection">9.2.46 abort, continue, muffle-warning, store-value, use-value [Function]</h4>
46
47 <span id="index-abort"></span>
48
49 <span id="index-continue"></span>
50
51 <span id="index-muffle_002dwarning"></span>
52
53 <span id="index-store_002dvalue"></span>
54
55 <span id="index-use_002dvalue"></span>
56
57 <p><code>abort</code> <i><span class="roman">&amp;optional</span> condition</i>
58 &rArr; #&lt;NoValue&gt;
59 </p>
60 <p><code>continue</code> <i><span class="roman">&amp;optional</span> condition</i> &rArr; <i><b>nil</b></i>
61 </p>
62 <p><code>muffle-warning</code> <i><span class="roman">&amp;optional</span> condition</i>
63 &rArr; #&lt;NoValue&gt;
64 </p>
65 <p><code>store-value</code> <i>value <span class="roman">&amp;optional</span> condition</i> &rArr; <i><b>nil</b></i>
66 </p>
67 <p><code>use-value</code> <i>value <span class="roman">&amp;optional</span> condition</i> &rArr; <i><b>nil</b></i>
68 </p>
69 <span id="Arguments-and-Values_003a_003a-157"></span><h4 class="subsubheading">Arguments and Values::</h4>
70
71 <p><i>value</i>&mdash;an <i>object</i>.
72 </p>
73 <p><i>condition</i>&mdash;a <i>condition</i> <i>object</i>, or <b>nil</b>.
74 </p>
75 <span id="Description_003a_003a-216"></span><h4 class="subsubheading">Description::</h4>
76
77 <p>Transfers control to the most recently established <i>applicable restart</i>
78 having the same name as the function. That is,
79 the <i>function</i> <b>abort</b> searches for an <i>applicable</i> <b>abort</b> <i>restart</i>,
80 the <i>function</i> <b>continue</b> searches for an <i>applicable</i> <b>continue</b> <i>restart</i>,
81 and so on.
82 </p>
83 <p>If no such <i>restart</i> exists,
84 the functions
85 <b>continue</b>,
86 <b>store-value</b>,
87 and <b>use-value</b>
88 return <b>nil</b>, and
89 the functions
90 <b>abort</b>
91 and <b>muffle-warning</b>
92 signal an error of <i>type</i> <b>control-error</b>.
93 </p>
94 <p>When <i>condition</i> is <i>non-nil</i>,
95 only those <i>restarts</i> are considered that are
96 either explicitly associated with that <i>condition</i>,
97 or not associated with any <i>condition</i>;
98 that is, the excluded <i>restarts</i> are
99 those that are associated with a non-empty set of <i>conditions</i>
100 of which the given <i>condition</i> is not an <i>element</i>.
101 If <i>condition</i> is <b>nil</b>, all <i>restarts</i> are considered.
102 </p>
103 <span id="Examples_003a_003a-140"></span><h4 class="subsubheading">Examples::</h4>
104
105 <div class="example">
106 <pre class="example">;;; Example of the ABORT retart
107
108 (defmacro abort-on-error (&amp;body forms)
109 `(handler-bind ((error #'abort))
110 ,@forms)) &rArr; ABORT-ON-ERROR
111 (abort-on-error (+ 3 5)) &rArr; 8
112 (abort-on-error (error &quot;You lose.&quot;))
113 <tt> |&gt; </tt> Returned to Lisp Top Level.
114
115 ;;; Example of the CONTINUE restart
116
117 (defun real-sqrt (n)
118 (when (minusp n)
119 (setq n (- n))
120 (cerror &quot;Return sqrt(~D) instead.&quot; &quot;Tried to take sqrt(-~D).&quot; n))
121 (sqrt n))
122
123 (real-sqrt 4) &rArr; 2
124 (real-sqrt -9)
125 <tt> |&gt; </tt> Error: Tried to take sqrt(-9).
126 <tt> |&gt; </tt> To continue, type :CONTINUE followed by an option number:
127 <tt> |&gt; </tt> 1: Return sqrt(9) instead.
128 <tt> |&gt; </tt> 2: Return to Lisp Toplevel.
129 <tt> |&gt; </tt> Debug&gt; <b>|&gt;&gt;</b><tt>(continue)</tt><b>&lt;&lt;|</b>
130 <tt> |&gt; </tt> Return sqrt(9) instead.
131 &rArr; 3
132
133 (handler-bind ((error #'(lambda (c) (continue))))
134 (real-sqrt -9)) &rArr; 3
135
136 ;;; Example of the MUFFLE-WARNING restart
137
138 (defun count-down (x)
139 (do ((counter x (1- counter)))
140 ((= counter 0) 'done)
141 (when (= counter 1)
142 (warn &quot;Almost done&quot;))
143 (format t &quot;~&amp;~D~
144 &rArr; COUNT-DOWN
145 (count-down 3)
146 <tt> |&gt; </tt> 3
147 <tt> |&gt; </tt> 2
148 <tt> |&gt; </tt> Warning: Almost done
149 <tt> |&gt; </tt> 1
150 &rArr; DONE
151 (defun ignore-warnings-while-counting (x)
152 (handler-bind ((warning #'ignore-warning))
153 (count-down x)))
154 &rArr; IGNORE-WARNINGS-WHILE-COUNTING
155 (defun ignore-warning (condition)
156 (declare (ignore condition))
157 (muffle-warning))
158 &rArr; IGNORE-WARNING
159 (ignore-warnings-while-counting 3)
160 <tt> |&gt; </tt> 3
161 <tt> |&gt; </tt> 2
162 <tt> |&gt; </tt> 1
163 &rArr; DONE
164
165 ;;; Example of the STORE-VALUE and USE-VALUE restarts
166
167 (defun careful-symbol-value (symbol)
168 (check-type symbol symbol)
169 (restart-case (if (boundp symbol)
170 (return-from careful-symbol-value
171 (symbol-value symbol))
172 (error 'unbound-variable
173 :name symbol))
174 (use-value (value)
175 :report &quot;Specify a value to use this time.&quot;
176 value)
177 (store-value (value)
178 :report &quot;Specify a value to store and use in the future.&quot;
179 (setf (symbol-value symbol) value))))
180 (setq a 1234) &rArr; 1234
181 (careful-symbol-value 'a) &rArr; 1234
182 (makunbound 'a) &rArr; A
183 (careful-symbol-value 'a)
184 <tt> |&gt; </tt> Error: A is not bound.
185 <tt> |&gt; </tt> To continue, type :CONTINUE followed by an option number.
186 <tt> |&gt; </tt> 1: Specify a value to use this time.
187 <tt> |&gt; </tt> 2: Specify a value to store and use in the future.
188 <tt> |&gt; </tt> 3: Return to Lisp Toplevel.
189 <tt> |&gt; </tt> Debug&gt; <b>|&gt;&gt;</b><tt>(use-value 12)</tt><b>&lt;&lt;|</b>
190 &rArr; 12
191 (careful-symbol-value 'a)
192 <tt> |&gt; </tt> Error: A is not bound.
193 <tt> |&gt; </tt> To continue, type :CONTINUE followed by an option number.
194 <tt> |&gt; </tt> 1: Specify a value to use this time.
195 <tt> |&gt; </tt> 2: Specify a value to store and use in the future.
196 <tt> |&gt; </tt> 3: Return to Lisp Toplevel.
197 <tt> |&gt; </tt> Debug&gt; <b>|&gt;&gt;</b><tt>(store-value 24)</tt><b>&lt;&lt;|</b>
198 &rArr; 24
199 (careful-symbol-value 'a)
200 &rArr; 24
201
202 ;;; Example of the USE-VALUE restart
203
204 (defun add-symbols-with-default (default &amp;rest symbols)
205 (handler-bind ((sys:unbound-symbol
206 #'(lambda (c)
207 (declare (ignore c))
208 (use-value default))))
209 (apply #'+ (mapcar #'careful-symbol-value symbols))))
210 &rArr; ADD-SYMBOLS-WITH-DEFAULT
211 (setq x 1 y 2) &rArr; 2
212 (add-symbols-with-default 3 'x 'y 'z) &rArr; 6
213
214 </pre></div>
215
216 <span id="Side-Effects_003a_003a-18"></span><h4 class="subsubheading">Side Effects::</h4>
217
218 <p>A transfer of control may occur if an appropriate <i>restart</i> is available,
219 or (in the case of the <i>function</i> <b>abort</b> or the <i>function</i> <b>muffle-warning</b>)
220 execution may be stopped.
221 </p>
222 <span id="Affected-By_003a_003a-35"></span><h4 class="subsubheading">Affected By::</h4>
223
224 <p>Each of these functions can be affected by
225 the presence of a <i>restart</i> having the same name.
226 </p>
227 <span id="Exceptional-Situations_003a_003a-49"></span><h4 class="subsubheading">Exceptional Situations::</h4>
228
229 <p>If an appropriate <b>abort</b> <i>restart</i>
230 is not available for the <i>function</i> <b>abort</b>,
231 or an appropriate <b>muffle-warning</b> <i>restart</i>
232 is not available for the <i>function</i> <b>muffle-warning</b>,
233 an error of <i>type</i> <b>control-error</b> is signaled.
234 </p>
235 <span id="See-Also_003a_003a-190"></span><h4 class="subsubheading">See Also::</h4>
236
237 <p><a href="invoke_002drestart.html">invoke-restart</a>
238 ,
239 <a href="Restarts.html">Restarts</a>,
240 <a href="Interfaces-to-Restarts.html">Interfaces to Restarts</a>,
241 <a href="assert.html">assert</a>
242 ,
243 <b>ccase</b>,
244 <a href="cerror.html">cerror</a>
245 ,
246 <a href="check_002dtype.html">check-type</a>
247 ,
248 <b>ctypecase</b>,
249 <a href="use_002dvalue.html">use-value</a>
250 ,
251 <a href="warn.html">warn</a>
252 </p>
253 <span id="Notes_003a_003a-114"></span><h4 class="subsubheading">Notes::</h4>
254
255 <div class="example">
256 <pre class="example"> (abort condition) &equiv; (invoke-restart 'abort)
257 (muffle-warning) &equiv; (invoke-restart 'muffle-warning)
258 (continue) &equiv; (let ((r (find-restart 'continue))) (if r (invoke-restart r)))
259 (use-value <i>x</i>) &equiv; (let ((r (find-restart 'use-value))) (if r (invoke-restart r <i>x</i>)))
260 (store-value x) &equiv; (let ((r (find-restart 'store-value))) (if r (invoke-restart r <i>x</i>)))
261 </pre></div>
262
263 <p>No functions defined in this specification are required to provide
264 a <b>use-value</b> <i>restart</i>.
265 </p>
266
267
268
269
270
271 <hr>
272 <div class="header">
273 <p>
274 Previous: <a href="use_002dvalue.html" accesskey="p" rel="prev">use-value</a>, Up: <a href="Conditions-Dictionary.html" accesskey="u" rel="up">Conditions Dictionary</a> &nbsp; </p>
275 </div>
276
277
278
279 </body>
280 </html>