186 lines
12 KiB
HTML
186 lines
12 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: Function ABORT, CONTINUE, MUFFLE-WARNING...</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="r_use_va.htm">
|
|
<LINK REL=UP HREF="c_condit.htm">
|
|
<LINK REL=NEXT HREF="10_.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="r_use_va.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_condit.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="10_.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="abort"><A NAME="continue"><A NAME="muffle-warning"><A NAME="store-value"><A NAME="use-value"><I>Function</I> <B>ABORT, CONTINUE, MUFFLE-WARNING, STORE-VALUE, USE-VALUE</B></A></A></A></A></A> <P>
|
|
<P><B>Syntax:</B><P>
|
|
<P>
|
|
|
|
<B>abort</B> <I><TT>&optional</TT> condition</I> =>| <P>
|
|
|
|
<B>continue</B> <I><TT>&optional</TT> condition</I> => <I><A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A></I><P>
|
|
|
|
<B>muffle-warning</B> <I><TT>&optional</TT> condition</I> =>| <P>
|
|
|
|
<B>store-value</B> <I>value <TT>&optional</TT> condition</I> => <I><A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A></I><P>
|
|
|
|
<B>use-value</B> <I>value <TT>&optional</TT> condition</I> => <I><A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A></I><P>
|
|
<P>
|
|
<P><B>Arguments and Values:</B><P>
|
|
<P>
|
|
<I>value</I>---an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
|
|
<I>condition</I>---a <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>, or <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
Transfers control to the most recently established <A REL=DEFINITION HREF="26_glo_a.htm#applicable_restart"><I>applicable restart</I></A> having the same name as the function. That is, the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="#abort"><B>abort</B></A> searches for an <A REL=DEFINITION HREF="26_glo_a.htm#applicable"><I>applicable</I></A> <A REL=DEFINITION HREF="a_abort.htm#abort"><B>abort</B></A> <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A>, the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="#continue"><B>continue</B></A> searches for an <A REL=DEFINITION HREF="26_glo_a.htm#applicable"><I>applicable</I></A> <A REL=DEFINITION HREF="a_contin.htm#continue"><B>continue</B></A> <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A>, and so on. <P>
|
|
If no such <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A> exists, the functions <A REL=DEFINITION HREF="#continue"><B>continue</B></A>, <A REL=DEFINITION HREF="#store-value"><B>store-value</B></A>, and <A REL=DEFINITION HREF="#use-value"><B>use-value</B></A> return <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>, and the functions <A REL=DEFINITION HREF="#abort"><B>abort</B></A> and <A REL=DEFINITION HREF="#muffle-warning"><B>muffle-warning</B></A> signal an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_contro.htm#control-error"><B>control-error</B></A>. <P>
|
|
When <I>condition</I> is <A REL=DEFINITION HREF="26_glo_n.htm#non-nil"><I>non-nil</I></A>, only those <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restarts</I></A> are considered that are either explicitly associated with that <I>condition</I>, or not associated with any <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A>; that is, the excluded <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restarts</I></A> are those that are associated with a non-empty set of <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>conditions</I></A> of which the given <I>condition</I> is not an <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>element</I></A>. If <I>condition</I> is <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>, all <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restarts</I></A> are considered. <P>
|
|
<P><B>Examples:</B><P>
|
|
<P>
|
|
<PRE>
|
|
;;; Example of the ABORT retart
|
|
|
|
(defmacro abort-on-error (&body forms)
|
|
`(handler-bind ((error #'abort))
|
|
,@forms)) => ABORT-ON-ERROR
|
|
(abort-on-error (+ 3 5)) => 8
|
|
(abort-on-error (error "You lose."))
|
|
>> Returned to Lisp Top Level.
|
|
|
|
;;; Example of the CONTINUE restart
|
|
|
|
(defun real-sqrt (n)
|
|
(when (minusp n)
|
|
(setq n (- n))
|
|
(cerror "Return sqrt(~D) instead." "Tried to take sqrt(-~D)." n))
|
|
(sqrt n))
|
|
|
|
(real-sqrt 4) => 2
|
|
(real-sqrt -9)
|
|
>> Error: Tried to take sqrt(-9).
|
|
>> To continue, type :CONTINUE followed by an option number:
|
|
>> 1: Return sqrt(9) instead.
|
|
>> 2: Return to Lisp Toplevel.
|
|
>> Debug> (continue)
|
|
>> Return sqrt(9) instead.
|
|
=> 3
|
|
|
|
(handler-bind ((error #'(lambda (c) (continue))))
|
|
(real-sqrt -9)) => 3
|
|
|
|
;;; Example of the MUFFLE-WARNING restart
|
|
|
|
(defun count-down (x)
|
|
(do ((counter x (1- counter)))
|
|
((= counter 0) 'done)
|
|
(when (= counter 1)
|
|
(warn "Almost done"))
|
|
(format t "~&~D~%" counter)))
|
|
=> COUNT-DOWN
|
|
(count-down 3)
|
|
>> 3
|
|
>> 2
|
|
>> Warning: Almost done
|
|
>> 1
|
|
=> DONE
|
|
(defun ignore-warnings-while-counting (x)
|
|
(handler-bind ((warning #'ignore-warning))
|
|
(count-down x)))
|
|
=> IGNORE-WARNINGS-WHILE-COUNTING
|
|
(defun ignore-warning (condition)
|
|
(declare (ignore condition))
|
|
(muffle-warning))
|
|
=> IGNORE-WARNING
|
|
(ignore-warnings-while-counting 3)
|
|
>> 3
|
|
>> 2
|
|
>> 1
|
|
=> DONE
|
|
|
|
;;; Example of the STORE-VALUE and USE-VALUE restarts
|
|
|
|
(defun careful-symbol-value (symbol)
|
|
(check-type symbol symbol)
|
|
(restart-case (if (boundp symbol)
|
|
(return-from careful-symbol-value
|
|
(symbol-value symbol))
|
|
(error 'unbound-variable
|
|
:name symbol))
|
|
(use-value (value)
|
|
:report "Specify a value to use this time."
|
|
value)
|
|
(store-value (value)
|
|
:report "Specify a value to store and use in the future."
|
|
(setf (symbol-value symbol) value))))
|
|
(setq a 1234) => 1234
|
|
(careful-symbol-value 'a) => 1234
|
|
(makunbound 'a) => A
|
|
(careful-symbol-value 'a)
|
|
>> Error: A is not bound.
|
|
>> To continue, type :CONTINUE followed by an option number.
|
|
>> 1: Specify a value to use this time.
|
|
>> 2: Specify a value to store and use in the future.
|
|
>> 3: Return to Lisp Toplevel.
|
|
>> Debug> (use-value 12)
|
|
=> 12
|
|
(careful-symbol-value 'a)
|
|
>> Error: A is not bound.
|
|
>> To continue, type :CONTINUE followed by an option number.
|
|
>> 1: Specify a value to use this time.
|
|
>> 2: Specify a value to store and use in the future.
|
|
>> 3: Return to Lisp Toplevel.
|
|
>> Debug> (store-value 24)
|
|
=> 24
|
|
(careful-symbol-value 'a)
|
|
=> 24
|
|
|
|
;;; Example of the USE-VALUE restart
|
|
|
|
(defun add-symbols-with-default (default &rest symbols)
|
|
(handler-bind ((sys:unbound-symbol
|
|
#'(lambda (c)
|
|
(declare (ignore c))
|
|
(use-value default))))
|
|
(apply #'+ (mapcar #'careful-symbol-value symbols))))
|
|
=> ADD-SYMBOLS-WITH-DEFAULT
|
|
(setq x 1 y 2) => 2
|
|
(add-symbols-with-default 3 'x 'y 'z) => 6
|
|
|
|
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Side Effects:</B><P>
|
|
<P>
|
|
A transfer of control may occur if an appropriate <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A> is available, or (in the case of the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="#abort"><B>abort</B></A> or the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="#muffle-warning"><B>muffle-warning</B></A>) execution may be stopped. <P>
|
|
<P><B>Affected By:</B><P>
|
|
<P>
|
|
Each of these functions can be affected by the presence of a <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A> having the same name. <P>
|
|
<P><B>Exceptional Situations:</B><P>
|
|
<P>
|
|
If an appropriate <A REL=DEFINITION HREF="a_abort.htm#abort"><B>abort</B></A> <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A> is not available for the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="#abort"><B>abort</B></A>, or an appropriate <A REL=DEFINITION HREF="a_muffle.htm#muffle-warning"><B>muffle-warning</B></A> <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A> is not available for the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="#muffle-warning"><B>muffle-warning</B></A>, an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_contro.htm#control-error"><B>control-error</B></A> is signaled. <P>
|
|
<P><B>See Also:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="f_invo_1.htm#invoke-restart"><B>invoke-restart</B></A>, <A REL=CHILD HREF="09_adb.htm">Section 9.1.4.2 (Restarts)</A>, <A REL=CHILD HREF="09_adbb.htm">Section 9.1.4.2.2 (Interfaces to Restarts)</A>, <A REL=DEFINITION HREF="m_assert.htm#assert"><B>assert</B></A>, <A REL=DEFINITION HREF="m_case_.htm#ccase"><B>ccase</B></A>, <A REL=DEFINITION HREF="f_cerror.htm#cerror"><B>cerror</B></A>, <A REL=DEFINITION HREF="m_check_.htm#check-type"><B>check-type</B></A>, <A REL=DEFINITION HREF="m_tpcase.htm#ctypecase"><B>ctypecase</B></A>, <A REL=DEFINITION HREF="#use-value"><B>use-value</B></A>, <A REL=DEFINITION HREF="f_warn.htm#warn"><B>warn</B></A> <P>
|
|
<P><B>Notes:</B><P>
|
|
<P>
|
|
<PRE>
|
|
(abort condition) == (invoke-restart 'abort)
|
|
(muffle-warning) == (invoke-restart 'muffle-warning)
|
|
(continue) == (let ((r (find-restart 'continue))) (if r (invoke-restart r)))
|
|
(use-value x) == (let ((r (find-restart 'use-value))) (if r (invoke-restart r x)))
|
|
(store-value x) == (let ((r (find-restart 'store-value))) (if r (invoke-restart r x)))
|
|
</PRE>
|
|
</TT> <P>
|
|
No functions defined in this specification are required to provide a <A REL=DEFINITION HREF="a_use_va.htm#use-value"><B>use-value</B></A> <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A>. <P>
|
|
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss244.htm">MUFFLE-WARNING-CONDITION-ARGUMENT</A><LI> <A REL=CHILD HREF="../Issues/iss076.htm">CONDITION-RESTARTS:PERMIT-ASSOCIATION</A><P></UL><HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|