253 lines
17 KiB
HTML
253 lines
17 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: Issue CONDITION-RESTARTS Writeup</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="../Issues/iss074_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss075_m.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss077_w.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="../Issues/iss074_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss075_m.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss077_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue CONDITION-RESTARTS Writeup</H2>
|
|
|
|
<PRE><B>Status:</B> Version 2, Passed, Jun 89 X3J13<P>
|
|
Version 3, as amended & passed Nov 89 X3J13<P>
|
|
<P>
|
|
<B>Issue:</B> <A HREF="iss075_m.htm">CONDITION-RESTARTS</A><P>
|
|
<B>Forum:</B> Cleanup<P>
|
|
<B>References:</B> Common Lisp Condition System<P>
|
|
<B>Category:</B> CHANGE<P>
|
|
<B>Edit history:</B> 18-Jan-89, Version 1 by Pitman<P>
|
|
26-Jun-89, Version 2 by Pitman and Barrett<P>
|
|
3-Dec-89, Version 3 by Masinter (as amended Nov 89 X3J13)<P>
|
|
<P>
|
|
<B>Problem Description:<P>
|
|
</B><P>
|
|
It was noted in the condition system document itself, and many people have<P>
|
|
complained privately, that a major weakness of the condition system is the<P>
|
|
inability to know whether a particular restart is associated with a <P>
|
|
particular signalling action. Also, there has been an interest in<P>
|
|
disabling an established restart in some situations.<P>
|
|
<P>
|
|
The problem being addressed shows itself in situations involving recursive<P>
|
|
errors. The programmer wants to make sure that a restart obtained from<P>
|
|
<A REL=DEFINITION HREF="../Body/f_find_r.htm#find-restart"><B>FIND-RESTART</B></A> or <A REL=DEFINITION HREF="../Body/f_comp_1.htm#compute-restarts"><B>COMPUTE-RESTARTS</B></A> is in fact present for the purpose of<P>
|
|
handling some particular error that he is actively focussed on, and not<P>
|
|
for some other (outer) error which he was not actively trying to handle.<P>
|
|
<P>
|
|
Also, some implementors have wondered whether it was appropriate to<P>
|
|
implement restarts as objects with dynamic extent. It would be good<P>
|
|
to make this clear so that users are not surprised when porting programs.<P>
|
|
<P>
|
|
<B>Proposal (CONDITION-RESTARTS:PERMIT-ASSOCIATION):<P>
|
|
</B><P>
|
|
1. Define that during the dynamic extent of a call to <A REL=DEFINITION HREF="../Body/f_signal.htm#signal"><B>SIGNAL</B></A> with a<P>
|
|
particular condition, the effect of calling <A REL=DEFINITION HREF="../Body/f_signal.htm#signal"><B>SIGNAL</B></A> again on that<P>
|
|
condition object for a distinct abstract event is not defined.<P>
|
|
<P>
|
|
For example, although a handler MAY resignal a condition in order to<P>
|
|
allow outer handlers first shot at handling the condition, two<P>
|
|
distinct asynchronous keyboard events may not signal an <A REL=DEFINITION HREF="../Body/f_eq.htm#eq"><B>EQ</B></A> condition<P>
|
|
object at the same time.<P>
|
|
<P>
|
|
2. Define that restarts have dynamic extent.<P>
|
|
<P>
|
|
3. Introduce a macro <A REL=DEFINITION HREF="../Body/m_w_cnd_.htm#with-condition-restarts"><B>WITH-CONDITION-RESTARTS</B></A> which can be used to<P>
|
|
dynamically bind the association between a condition and a set<P>
|
|
of restarts.<P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="../Body/m_w_cnd_.htm#with-condition-restarts"><B>WITH-CONDITION-RESTARTS</B></A> condition-form restarts-form <A REL=DEFINITION HREF="../Body/03_dd.htm#AMbody"><B>&BODY</B></A> forms<P>
|
|
[Macro]<P>
|
|
<P>
|
|
Evaluates CONDITION-FORM and RESTARTS-FORM, the results of which<P>
|
|
should be a condition C and a list of restarts (R1 R2 ...),<P>
|
|
respectively. Then evaluates the body of forms in implicit-progn<P>
|
|
style, returning the result of the last form, or <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> if there<P>
|
|
are no forms. While in the dynamic context of the body,<P>
|
|
an attempt to find a restart Ri which is associated with a<P>
|
|
condition Ci (see #4 below), as in (<A REL=DEFINITION HREF="../Body/f_find_r.htm#find-restart"><B>FIND-RESTART</B></A> rI cI), will <P>
|
|
consider the restarts R1, R2, etc. if (<A REL=DEFINITION HREF="../Body/f_eq.htm#eq"><B>EQ</B></A> CI C).<P>
|
|
<P>
|
|
Usually this macro is not used explicitly in code, since<P>
|
|
<A REL=DEFINITION HREF="../Body/m_rst_ca.htm#restart-case"><B>RESTART-CASE</B></A> handles most of the common cases in a way that is<P>
|
|
syntactically more concise.<P>
|
|
<P>
|
|
4. Extend <A REL=DEFINITION HREF="../Body/f_comp_1.htm#compute-restarts"><B>COMPUTE-RESTARTS</B></A>, <A REL=DEFINITION HREF="../Body/f_find_r.htm#find-restart"><B>FIND-RESTART</B></A>, <A REL=DEFINITION HREF="../Body/a_abort.htm#abort"><B>ABORT</B></A>, <A REL=DEFINITION HREF="../Body/a_contin.htm#continue"><B>CONTINUE</B></A>, <A REL=DEFINITION HREF="../Body/a_use_va.htm#use-value"><B>USE-VALUE</B></A>,<P>
|
|
and <A REL=DEFINITION HREF="../Body/a_store_.htm#store-value"><B>STORE-VALUE</B></A> to permit an optional condition object as an argument.<P>
|
|
<P>
|
|
When the extra argument is not supplied, these functions behave<P>
|
|
exactly as defined before. (Restarts are considered without<P>
|
|
prejudice to whether they have been associated with conditions.)<P>
|
|
<P>
|
|
When this argument is supplied, only those restarts which are<P>
|
|
associated with the given condition or restarts which are not<P>
|
|
associated with any condition are considered. In all other<P>
|
|
respects, the behavior is the same. [However, see #7 for related<P>
|
|
developments.]<P>
|
|
<P>
|
|
Passing a condition argument of <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> is treated the same as passing<P>
|
|
no condition argument.<P>
|
|
<P>
|
|
5. Extend the definition of <A REL=DEFINITION HREF="../Body/m_rst_ca.htm#restart-case"><B>RESTART-CASE</B></A> to say that if the form to<P>
|
|
do the signalling is a list whose <A REL=DEFINITION HREF="../Body/f_car_c.htm#car"><B>car</B></A> is any of <A REL=DEFINITION HREF="../Body/f_signal.htm#signal"><B>SIGNAL</B></A>, <A REL=DEFINITION HREF="../Body/a_error.htm#error"><B>ERROR</B></A>,<P>
|
|
<A REL=DEFINITION HREF="../Body/f_cerror.htm#cerror"><B>CERROR</B></A>, or <A REL=DEFINITION HREF="../Body/f_warn.htm#warn"><B>WARN</B></A> (or is a form which macroexpands into such a<P>
|
|
list), then <A REL=DEFINITION HREF="../Body/m_w_cnd_.htm#with-condition-restarts"><B>WITH-CONDITION-RESTARTS</B></A> is implicitly intended to<P>
|
|
associate the restarts with the condition to be signalled.<P>
|
|
<P>
|
|
That is, for example,<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_rst_ca.htm#restart-case"><B>RESTART-CASE</B></A> (<A REL=DEFINITION HREF="../Body/f_signal.htm#signal"><B>SIGNAL</B></A> FRED)<P>
|
|
(A ...)<P>
|
|
(B ...))<P>
|
|
is equivalent to<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_rst_ca.htm#restart-case"><B>RESTART-CASE</B></A><P>
|
|
(<A REL=DEFINITION HREF="../Body/m_w_cnd_.htm#with-condition-restarts"><B>WITH-CONDITION-RESTARTS</B></A> FRED <P>
|
|
(<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A> (<A REL=DEFINITION HREF="../Body/f_find_r.htm#find-restart"><B>FIND-RESTART</B></A> 'A) <P>
|
|
(<A REL=DEFINITION HREF="../Body/f_find_r.htm#find-restart"><B>FIND-RESTART</B></A> 'B))<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_signal.htm#signal"><B>SIGNAL</B></A> FRED))<P>
|
|
(A ...)<P>
|
|
(B ...))<P>
|
|
<P>
|
|
6. Define that Common Lisp macros such as <A REL=DEFINITION HREF="../Body/m_check_.htm#check-type"><B>CHECK-TYPE</B></A>, which are defined<P>
|
|
to signal and to make restarts available, use the equivalent of<P>
|
|
<A REL=DEFINITION HREF="../Body/m_w_cnd_.htm#with-condition-restarts"><B>WITH-CONDITION-RESTARTS</B></A> to associate the conditions they signal with<P>
|
|
the defined restarts, so that users can make reliable tests not only<P>
|
|
for the restarts being available, but also for them being available<P>
|
|
for the right reasons.<P>
|
|
<P>
|
|
7. Add a :TEST keyword to <A REL=DEFINITION HREF="../Body/m_rst_ca.htm#restart-case"><B>RESTART-CASE</B></A> clauses and a :TEST-FUNCTION<P>
|
|
keyword to <A REL=DEFINITION HREF="../Body/m_rst_bi.htm#restart-bind"><B>RESTART-BIND</B></A> clauses (in the same general style as the<P>
|
|
:INTERACTIVE and :INTERACTIVE-FUNCTION keywords). These permit<P>
|
|
association of a function of one argument with a restart such<P>
|
|
that if this function returns false, then functions such as<P>
|
|
<A REL=DEFINITION HREF="../Body/f_find_r.htm#find-restart"><B>FIND-RESTART</B></A>, <A REL=DEFINITION HREF="../Body/f_comp_1.htm#compute-restarts"><B>COMPUTE-RESTARTS</B></A>, and <A REL=DEFINITION HREF="../Body/f_invo_1.htm#invoke-restart"><B>INVOKE-RESTART</B></A> [see #4 above]<P>
|
|
will not consider the restart to be active. The argument to the<P>
|
|
test function is the value of the optional condition argument<P>
|
|
most of these functions accept (or nil for <A REL=DEFINITION HREF="../Body/f_invo_1.htm#invoke-restart"><B>invoke-restart</B></A>, since<P>
|
|
it doesn't have that argument). The default test function is<P>
|
|
<P>
|
|
#'(<A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>LAMBDA</B></A> (C) (<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/d_ignore.htm#ignore"><B>IGNORE</B></A> C)) T).<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B><P>
|
|
1. The ability to recycle a condition object (including the ability to<P>
|
|
resignal a condition) means that the same condition object might be<P>
|
|
simultaneously active for two different purposes. In such a case, no<P>
|
|
test (not even <A REL=DEFINITION HREF="../Body/f_eq.htm#eq"><B>EQ</B></A>) would suffice to determine whether a particular<P>
|
|
restart belonged with a particular signalling action, since the<P>
|
|
condition could not uniquely identify the signalling action. By<P>
|
|
making the programmer responsible for assuring that that a given<P>
|
|
condition may not be concurrently signalled for two conceptually<P>
|
|
distinct purposes, this sticky area is avoided.<P>
|
|
<P>
|
|
2. There are no known reasons for restarts to not have dynamic extent.<P>
|
|
Important optimizations may be possible by allowing implementors this<P>
|
|
flexibility.<P>
|
|
<P>
|
|
3. This is is the minimal level of support needed to set up an <P>
|
|
association between restarts and conditions.<P>
|
|
<P>
|
|
4. This provides a natural interface for retrieving and using the<P>
|
|
information about the associations between conditions and restarts.<P>
|
|
<P>
|
|
5. This provides a natural interface for the most common case of<P>
|
|
wanting to signal a restart with some associated conditions.<P>
|
|
<P>
|
|
6. This is a logical consequence of 5.<P>
|
|
<P>
|
|
7. Programmers and implementors have asked for a way of<P>
|
|
"filtering" restarts so that they are not visible in some contexts.<P>
|
|
<P>
|
|
<B>Test Case:<P>
|
|
</B><P>
|
|
(<A REL=DEFINITION HREF="../Body/m_handle.htm#handler-bind"><B>HANDLER-BIND</B></A> ((<A REL=DEFINITION HREF="../Body/a_error.htm#error"><B>ERROR</B></A> #'(<A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>LAMBDA</B></A> (C) (<A REL=DEFINITION HREF="../Body/f_signal.htm#signal"><B>SIGNAL</B></A> C) ...))) (<A REL=DEFINITION HREF="../Body/f_signal.htm#signal"><B>SIGNAL</B></A> "Test"))<P>
|
|
was permissible and continues to be. However,<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_handle.htm#handler-bind"><B>HANDLER-BIND</B></A> ((<A REL=DEFINITION HREF="../Body/a_error.htm#error"><B>ERROR</B></A> #'(<A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>LAMBDA</B></A> (C) (<A REL=DEFINITION HREF="../Body/f_signal.htm#signal"><B>SIGNAL</B></A> FRED) ...))) (<A REL=DEFINITION HREF="../Body/f_signal.htm#signal"><B>SIGNAL</B></A> FRED))<P>
|
|
may be undefined (depending on the programmer's intent) because the<P>
|
|
two uses of FRED are not cooperating and may not represent conceptually<P>
|
|
distinct situations.<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_rst_ca.htm#restart-case"><B>RESTART-CASE</B></A> <P>
|
|
(<A REL=DEFINITION HREF="../Body/m_w_cnd_.htm#with-condition-restarts"><B>WITH-CONDITION-RESTARTS</B></A> FOO (<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A> (<A REL=DEFINITION HREF="../Body/f_find_r.htm#find-restart"><B>FIND-RESTART</B></A> 'ALPHA))<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_rst_ca.htm#restart-case"><B>RESTART-CASE</B></A><P>
|
|
(<A REL=DEFINITION HREF="../Body/f_invo_1.htm#invoke-restart"><B>INVOKE-RESTART</B></A> 'ALPHA)<P>
|
|
(ALPHA () 2)))<P>
|
|
(ALPHA () 1)))<P>
|
|
=> 2<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> ((FOO (<A REL=DEFINITION HREF="../Body/f_mk_cnd.htm#make-condition"><B>MAKE-CONDITION</B></A> '<A REL=DEFINITION HREF="../Body/e_smp_cn.htm#simple-condition"><B>SIMPLE-CONDITION</B></A>)))<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_rst_ca.htm#restart-case"><B>RESTART-CASE</B></A> <P>
|
|
(<A REL=DEFINITION HREF="../Body/m_w_cnd_.htm#with-condition-restarts"><B>WITH-CONDITION-RESTARTS</B></A> FOO (<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A> (<A REL=DEFINITION HREF="../Body/f_find_r.htm#find-restart"><B>FIND-RESTART</B></A> 'ALPHA))<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_rst_ca.htm#restart-case"><B>RESTART-CASE</B></A><P>
|
|
(<A REL=DEFINITION HREF="../Body/f_invo_1.htm#invoke-restart"><B>INVOKE-RESTART</B></A> (<A REL=DEFINITION HREF="../Body/f_find_r.htm#find-restart"><B>FIND-RESTART</B></A> 'ALPHA FOO))<P>
|
|
(ALPHA () 2)))<P>
|
|
(ALPHA () 1)))<P>
|
|
=> 1<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_rst_ca.htm#restart-case"><B>RESTART-CASE</B></A> <P>
|
|
(<A REL=DEFINITION HREF="../Body/m_w_cnd_.htm#with-condition-restarts"><B>WITH-CONDITION-RESTARTS</B></A> FOO (<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A> (<A REL=DEFINITION HREF="../Body/f_find_r.htm#find-restart"><B>FIND-RESTART</B></A> 'ALPHA))<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_rst_ca.htm#restart-case"><B>RESTART-CASE</B></A><P>
|
|
(<A REL=DEFINITION HREF="../Body/f_invo_1.htm#invoke-restart"><B>INVOKE-RESTART</B></A> 'ALPHA)<P>
|
|
(ALPHA () :TEST (<A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>LAMBDA</B></A> (C) (<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/d_ignore.htm#ignore"><B>IGNORE</B></A> C)) <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>)<P>
|
|
2)))<P>
|
|
(ALPHA () 1)))<P>
|
|
=> 1<P>
|
|
<P>
|
|
<B>Current Practice:<P>
|
|
</B><P>
|
|
Presumably no implementation does this yet.<P>
|
|
<P>
|
|
<B>Cost to Implementors:<P>
|
|
</B><P>
|
|
Several small, relatively modular changes.<P>
|
|
<P>
|
|
The specific details of how the association is made between conditions<P>
|
|
and restarts is left up to the implementation. It is recommended (e.g.,<P>
|
|
for the sake of the garbage collector) that the association be external<P>
|
|
to the condition, however, since the condition might persist for long<P>
|
|
afterward and the restart information has no value beyond the dynamic<P>
|
|
extent during which the actual signalling is occurring.<P>
|
|
<P>
|
|
<B>Cost to Users:<P>
|
|
</B><P>
|
|
Except for the change to the recyclability of restarts, this change is <P>
|
|
upward compatible.<P>
|
|
<P>
|
|
Probably very few if any users currently take advantage of recycling<P>
|
|
restarts, so the cost to users of this change is very slight.<P>
|
|
<P>
|
|
<B>Cost of Non-Adoption:<P>
|
|
</B><P>
|
|
Use of restarts would not be nearly as reliable.<P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B><P>
|
|
It would be possible to write code which was considerably more robust.<P>
|
|
<P>
|
|
<B>Aesthetics:<P>
|
|
</B><P>
|
|
Some people might consider this proposal to make things slightly better<P>
|
|
because it avoids some ambiguities. Others might consider it to make<P>
|
|
things slightly worse because it adds additional complexity.<P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
Pitman and Barrett support this proposal.<P>
|
|
</PRE>
|
|
<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>
|