concept-conditions.tex 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. % -*- Mode: TeX -*-
  2. %% Errors
  3. %% CONDITION-RESTARTS hasn't been included
  4. %!!! What to do with this use of "construct"? -kmp 3-Sep-91
  5. Common Lisp constructs are described not only in terms of their
  6. behavior in situations during which they are intended to be used (see
  7. the ``Description'' part of each \term{operator} specification),
  8. but in all other situations (see the ``Exceptional Situations''
  9. part of each \term{operator} specification).
  10. A situation is the evaluation of an expression in a specific context.
  11. %at a particular point in time? -kmp 5-Sep-91
  12. A \term{condition} is an \term{object} that
  13. represents a specific situation that has been detected.
  14. \term{Conditions} are \instancesofclasses{condition}.
  15. A hierarchy of \term{condition} classes is defined in \clisp.
  16. A \term{condition} has \term{slots} that contain data
  17. relevant to the situation that the \term{condition} represents.
  18. An error is a situation in which normal program execution cannot
  19. continue correctly without some form of intervention (either
  20. interactively by the user or under program control). Not all errors
  21. are detected. When an error goes undetected, the effects can be
  22. \term{implementation-dependent}, \term{implementation-defined}, unspecified, or
  23. undefined. \Seesection\Definitions. All detected errors can
  24. be represented by \term{conditions}, but not all
  25. \term{conditions} represent errors.
  26. Signaling is the process by which a \term{condition} can alter
  27. the flow of control in a program by raising the
  28. \term{condition} which can then be \term{handled}. The functions
  29. \funref{error}, \funref{cerror}, \funref{signal}, and
  30. \funref{warn} are used to signal \term{conditions}.
  31. The process of signaling involves the selection and invocation of a
  32. \term{handler} from a set of \term{active} \term{handlers}.
  33. A \term{handler} is a \term{function} of one argument (the
  34. \term{condition}) that is invoked to handle a \term{condition}.
  35. Each \term{handler} is associated with a \term{condition} \term{type},
  36. and a \term{handler} will be invoked only on a \term{condition} of the
  37. \term{handler}'s associated \term{type}.
  38. \term{Active} \term{handlers} are \term{established} dynamically
  39. (see \macref{handler-bind} or \macref{handler-case}).
  40. \term{Handlers} are invoked in a \term{dynamic environment}
  41. equivalent to that of the signaler,
  42. except that the set of \term{active} \term{handlers}
  43. is bound in such a way as to include only those that were \term{active}
  44. at the time the \term{handler} being invoked was \term{established}.
  45. Signaling a \term{condition} has no side-effect on the \term{condition},
  46. and there is no dynamic state contained in a \term{condition}.
  47. If a \term{handler} is invoked, it can address the \term{situation}
  48. in one of three ways:
  49. \beginlist
  50. \itemitem{\b{Decline}}
  51. It can decline to \term{handle} the \term{condition}. It does this by
  52. simply returning rather than transferring control.
  53. When this happens, any values returned by the handler are
  54. ignored and the next most recently established handler is invoked.
  55. If there is no such handler and the signaling function is \funref{error}
  56. or \funref{cerror}, the debugger is entered in the
  57. \term{dynamic environment} of the signaler. If there is no such
  58. handler and the signaling function is either \funref{signal} or
  59. \funref{warn}, the signaling function simply returns~\nil.
  60. \itemitem{\b{Handle}}
  61. It can \term{handle} the \term{condition} by performing a non-local
  62. transfer of control. This can be done either primitively by using
  63. \specref{go}, \macref{return}, \specref{throw} or more
  64. abstractly by using a function such as \funref{abort} or
  65. \funref{invoke-restart}.
  66. \itemitem{\b{Defer}}
  67. It can put off a decision about whether to \term{handle} or \term{decline},
  68. by any of a number of actions, but most commonly by
  69. signaling another condition,
  70. resignaling the same condition,
  71. or forcing entry into the debugger.
  72. \endlist
  73. %%KMP
  74. %The latter two actions
  75. %are really just ways of putting off the decision to either \term{handle}
  76. %or decline. Ultimately,
  77. %all a handler can do is to \term{handle} or decline to \term{handle}.
  78. \beginSubsection{Condition Types}
  79. \Thenextfigure\ lists the \term{standardized} \term{condition} \term{types}.
  80. Additional \term{condition} \term{types} can be defined by using \macref{define-condition}.
  81. \issue{UNDEFINED-FUNCTIONS-AND-VARIABLES:COMPROMISE}
  82. \issue{DATA-IO:ADD-SUPPORT}
  83. \issue{PARSE-ERROR-STREAM:SPLIT-TYPES}
  84. \issue{ACCESS-ERROR-NAME}
  85. \issue{READER-ERROR:NEW-TYPE}
  86. \issue{FLOATING-POINT-CONDITION-NAMES:X3J13-NOV-89}
  87. \issue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  88. \DefineFigure{StandardizedConditionTypes}
  89. \displaythree{Standardized Condition Types}{
  90. arithmetic-error&floating-point-overflow&simple-type-error\cr
  91. cell-error&floating-point-underflow&simple-warning\cr
  92. condition&package-error&storage-condition\cr
  93. control-error&parse-error&stream-error\cr
  94. division-by-zero&print-not-readable&style-warning\cr
  95. end-of-file&program-error&type-error\cr
  96. error&reader-error&unbound-slot\cr
  97. file-error&serious-condition&unbound-variable\cr
  98. floating-point-inexact&simple-condition&undefined-function\cr
  99. floating-point-invalid-operation&simple-error&warning\cr
  100. }
  101. \endissue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  102. \endissue{FLOATING-POINT-CONDITION-NAMES:X3J13-NOV-89}
  103. \endissue{READER-ERROR:NEW-TYPE}
  104. \endissue{ACCESS-ERROR-NAME}
  105. \endissue{PARSE-ERROR-STREAM:SPLIT-TYPES}
  106. \endissue{DATA-IO:ADD-SUPPORT}
  107. \endissue{UNDEFINED-FUNCTIONS-AND-VARIABLES:COMPROMISE}
  108. All \term{condition} types are \subtypesof{condition}. That is,
  109. \code
  110. (typep \param{c} 'condition) \EV \term{true}
  111. \endcode
  112. if and only if \param{c} is a \term{condition}.
  113. \term{Implementations} must define all specified \term{subtype} relationships.
  114. %!!! Barrett: I don't understand this sentence.
  115. Except where noted, all \term{subtype} relationships indicated in
  116. this document are not mutually exclusive.
  117. A \term{condition} inherits the structure of its \term{supertypes}.
  118. %!!! Barrett: It would be easier to say that conditions are classes,
  119. % but maybe there is some reason to avoid doing so?
  120. The metaclass of \theclass{condition} is not specified.
  121. \term{Names} of \term{condition} \term{types} may be used to specify
  122. \term{supertype} relationships in \macref{define-condition},
  123. but the consequences are not specified if an attempt is made to use
  124. a \term{condition} \term{type} as a \term{superclass} in a \macref{defclass} \term{form}.
  125. % \Thenextfigure\ lists the \term{condition} \term{types} defined in this specification.
  126. %
  127. % \issue{UNDEFINED-FUNCTIONS-AND-VARIABLES:COMPROMISE}
  128. % \issue{DATA-IO:ADD-SUPPORT}
  129. % \issue{PARSE-ERROR-STREAM:SPLIT-TYPES}
  130. % \issue{ACCESS-ERROR-NAME}
  131. % \issue{READER-ERROR:NEW-TYPE}
  132. % \issue{FLOATING-POINT-CONDITION-NAMES:X3J13-NOV-89}
  133. % \issue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  134. % \displaythree{Condition Types}{
  135. % arithmetic-error&package-error&storage-condition\cr
  136. % cell-error&parse-error&stream-error\cr
  137. % condition&print-not-readable&style-warning\cr
  138. % control-error&program-error&type-error\cr
  139. % division-by-zero&reader-error&unbound-slot\cr
  140. % end-of-file&serious-condition&unbound-slot-instance\cr
  141. % error&simple-condition&unbound-variable\cr
  142. % file-error&simple-error&undefined-function\cr
  143. % floating-point-overflow&simple-type-error&warning\cr
  144. % floating-point-underflow&simple-warning&\cr
  145. % }
  146. % \endissue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  147. % \endissue{FLOATING-POINT-CONDITION-NAMES:X3J13-NOV-89}
  148. % \endissue{READER-ERROR:NEW-TYPE}
  149. % \endissue{ACCESS-ERROR-NAME}
  150. % \endissue{PARSE-ERROR-STREAM:SPLIT-TYPES}
  151. % \endissue{DATA-IO:ADD-SUPPORT}
  152. % \endissue{UNDEFINED-FUNCTIONS-AND-VARIABLES:COMPROMISE}
  153. \Thenextfigure\ shows \term{operators} that
  154. define \term{condition} \term{types} and creating \term{conditions}.
  155. \displaythree{Operators that define and create conditions.}{
  156. define-condition&make-condition&\cr
  157. }
  158. \Thenextfigure\ shows \term{operators} that \term{read}
  159. the \term{value} of \term{condition} \term{slots}.
  160. \issue{DATA-IO:ADD-SUPPORT}
  161. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  162. \displaytwo{Operators that read condition slots.}{
  163. arithmetic-error-operands&simple-condition-format-arguments\cr
  164. arithmetic-error-operation&simple-condition-format-control\cr
  165. cell-error-name&stream-error-stream\cr
  166. file-error-pathname&type-error-datum\cr
  167. package-error-package&type-error-expected-type\cr
  168. print-not-readable-object&unbound-slot-instance\cr
  169. }
  170. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  171. \endissue{DATA-IO:ADD-SUPPORT}
  172. \beginsubsubsection{Serious Conditions}
  173. A \term{serious condition} is a \term{condition} serious
  174. enough to require interactive intervention if not handled.
  175. \term{Serious conditions} are typically signaled with \funref{error} or \funref{cerror};
  176. non-serious \term{conditions} are typically signaled with \funref{signal} or \funref{warn}.
  177. %%Barrett: Definitional.
  178. %All \term{serious conditions} should be \subtypesof{serious-condition}.
  179. \endsubsubsection%{Serious Conditions}
  180. \endSubsection%{Condition Types}
  181. \beginsubsection{Creating Conditions}
  182. The function \funref{make-condition} can be used to construct
  183. a \term{condition} \term{object} explicitly. Functions such as \funref{error},
  184. \funref{cerror}, \funref{signal}, and \funref{warn} operate on
  185. \term{conditions} and might create \term{condition} \term{objects}
  186. implicitly. Macros such as \macref{ccase}, \macref{ctypecase},
  187. \macref{ecase}, \macref{etypecase}, \macref{check-type}, and
  188. \macref{assert} might also implicitly create (and \term{signal})
  189. \term{conditions}.
  190. \beginsubsubsection{Condition Designators}
  191. \DefineSection{ConditionDesignators}
  192. A number of the functions in the condition system take arguments which
  193. are identified as \newtermidx{condition designators}{condition designator}.
  194. By convention, those arguments are notated as
  195. \ \param{datum} {\rest} \param{arguments}
  196. Taken together, the \param{datum} and the \param{arguments} are
  197. ``\term{designators} for a \term{condition} of default type \param{default-type}.''
  198. How the denoted \term{condition} is computed depends on the type of the \param{datum}:
  199. \beginlist
  200. \item{{\bull} If the \param{datum} is a \term{symbol}
  201. naming a \term{condition} \term{type} $\ldots$}
  202. The denoted \term{condition} is the result of
  203. \code
  204. (apply #'make-condition \param{datum} \param{arguments})
  205. \endcode
  206. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  207. \item{{\bull} If the \param{datum} is a \term{format control} $\ldots$}
  208. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  209. The denoted \term{condition} is the result of
  210. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  211. \code
  212. (make-condition \param{defaulted-type}
  213. :format-control \param{datum}
  214. :format-arguments \param{arguments})
  215. \endcode
  216. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  217. %Barrett wanted this added so that implementations could do something more
  218. %elaborate than just the given type without interfering with user programs.
  219. %There's a lot of mail about simple-condition-disjointness-bug which might or
  220. %might not actually turn into a formal issue someday. -kmp 2-Feb-92
  221. where the \param{defaulted-type} is a \term{subtype} of \param{default-type}.
  222. \item{{\bull} If the \param{datum} is a \term{condition} $\ldots$}
  223. The denoted \term{condition} is the \param{datum} itself.
  224. In this case, unless otherwise specified by the description of the
  225. \term{operator} in question, the \term{arguments} must be \term{null};
  226. that is, the consequences are undefined if any \param{arguments} were supplied.
  227. \endlist
  228. Note that the \param{default-type} gets used only in the case where
  229. the \param{datum} \term{string} is supplied. In the other situations,
  230. the resulting condition is not necessarily of \term{type} \param{default-type}.
  231. Here are some illustrations of how different \term{condition designators}
  232. can denote equivalent \term{condition} \term{objects}:
  233. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  234. \code
  235. (let ((c (make-condition 'arithmetic-error :operator '/ :operands '(7 0))))
  236. (error c))
  237. \EQ (error 'arithmetic-error :operator '/ :operands '(7 0))
  238. (error "Bad luck.")
  239. \EQ (error 'simple-error :format-control "Bad luck." :format-arguments '())
  240. \endcode
  241. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  242. \endsubsubsection%{Condition Designators}
  243. \endsubsection%{Creating Conditions}
  244. \beginsubsection{Printing Conditions}
  245. \DefineSection{PrintingConditions}
  246. If the \kwd{report} argument to \macref{define-condition} is used,
  247. a print function is defined that is called whenever
  248. the defined \term{condition} is printed while \thevalueof{*print-escape*} is \term{false}.
  249. This function is called the \newterm{condition reporter};
  250. the text which it outputs is called a \newterm{report message}.
  251. When a \term{condition} is printed and \varref{*print-escape*}
  252. is \term{false}, the \term{condition reporter} for the \term{condition} is invoked.
  253. \term{Conditions} are printed automatically by functions such as
  254. \funref{invoke-debugger}, \funref{break}, and \funref{warn}.
  255. When \varref{*print-escape*} is \term{true}, the \term{object} should print in an
  256. abbreviated fashion according to the style of the implementation
  257. (\eg by \funref{print-unreadable-object}). It is not required that a
  258. \term{condition} can be recreated by reading its printed representation.
  259. No \term{function} is provided for directly \term{accessing}
  260. or invoking \term{condition reporters}.
  261. \beginsubsubsection{Recommended Style in Condition Reporting}
  262. In order to ensure a properly aesthetic result when presenting
  263. \term{report messages} to the user, certain stylistic conventions are
  264. recommended.
  265. There are stylistic recommendations for the content of the messages
  266. output by \term{condition reporters}, but there are no formal requirements
  267. on those \term{programs}.
  268. If a \term{program} violates the recommendations for some message, the
  269. display of that message might be less aesthetic than if the guideline
  270. had been observed, but the \term{program} is still considered a
  271. \term{conforming program}.
  272. The requirements on a \term{program} or \term{implementation} which
  273. invokes a \term{condition reporter} are somewhat stronger. A \term{conforming
  274. program} must be permitted to assume that if these style guidelines are
  275. followed, proper aesthetics will be maintained. Where appropriate, any
  276. specific requirements on such routines are explicitly mentioned below.
  277. \beginsubsubsubsection{Capitalization and Punctuation in Condition Reports}
  278. It is recommended that a \term{report message} be a complete sentences, in the
  279. proper case and correctly punctuated. In English, for example, this
  280. means the first letter should be uppercase, and there should be a
  281. trailing period.
  282. \code
  283. (error "This is a message") ; Not recommended
  284. (error "this is a message.") ; Not recommended
  285. (error "This is a message.") ; Recommended instead
  286. \endcode
  287. \endsubsubsubsection%{Capitalization and Punctuation in Condition Reports}
  288. \beginsubsubsubsection{Leading and Trailing Newlines in Condition Reports}
  289. It is recommended that a \term{report message} not begin with any
  290. introductory text, such as ``\f{Error: }'' or ``\f{Warning: }''
  291. or even just \term{freshline} or \term{newline}.
  292. Such text is added, if appropriate to the context,
  293. by the routine invoking the \term{condition reporter}.
  294. It is recommended that a \term{report message} not be followed
  295. by a trailing \term{freshline} or \term{newline}.
  296. Such text is added, if appropriate to the context,
  297. by the routine invoking the \term{condition reporter}.
  298. \code
  299. (error "This is a message.~%") ; Not recommended
  300. (error "~&This is a message.") ; Not recommended
  301. (error "~&This is a message.~%") ; Not recommended
  302. (error "This is a message.") ; Recommended instead
  303. \endcode
  304. \endsubsubsubsection%{Leading and Trailing Newlines in Condition Reports}
  305. \beginsubsubsubsection{Embedded Newlines in Condition Reports}
  306. Especially if it is long, it is permissible and appropriate for
  307. a \term{report message} to contain one or more embedded \term{newlines}.
  308. If the calling routine conventionally inserts some additional prefix
  309. (such as ``\f{Error: }'' or ``\f{;; Error: }'') on the first line of
  310. the message, it must also assure that an appropriate prefix will be
  311. added to each subsequent line of the output, so that the left edge of
  312. the message output by the \term{condition reporter} will still be properly
  313. aligned.
  314. \code
  315. (defun test ()
  316. (error "This is an error message.~\%It has two lines."))
  317. ;; Implementation A
  318. (test)
  319. This is an error message.
  320. It has two lines.
  321. ;; Implementation B
  322. (test)
  323. ;; Error: This is an error message.
  324. ;; It has two lines.
  325. ;; Implementation C
  326. (test)
  327. >> Error: This is an error message.
  328. It has two lines.
  329. \endcode
  330. \endsubsubsubsection%{Embedded Newlines in Condition Reports}
  331. \beginsubsubsubsection{Note about Tabs in Condition Reports}
  332. Because the indentation of a \term{report message} might be shifted to the right or
  333. left by an arbitrary amount, special care should be taken with the
  334. semi-standard \term{character} \TabChar\
  335. (in those \term{implementations} that support such a \term{character}).
  336. Unless the \term{implementation} specifically defines its behavior
  337. in this context, its use should be avoided.
  338. \endsubsubsubsection%{Note about Tabs in Condition Reports}
  339. \beginsubsubsubsection{Mentioning Containing Function in Condition Reports}
  340. The name of the containing function should generally not be mentioned in
  341. \term{report messages}. It is assumed that the \term{debugger} will make this
  342. information accessible in situations where it is necessary and appropriate.
  343. \endsubsubsubsection%{Mentioning Containing Function in Condition Reports}
  344. \endsubsubsection%{Recommended Style in Condition Reporting}
  345. \endsubsection%{Printing Conditions}
  346. \goodbreak
  347. \beginSubsection{Signaling and Handling Conditions}
  348. \DefineSection{CondSignalHandle}
  349. The operation of the condition system depends on the ordering of
  350. active \term{applicable handlers} from most recent to least recent.
  351. Each \term{handler} is associated with a \term{type specifier}
  352. that must designate a \subtypeof{condition}. A \term{handler}
  353. is said to be \term{applicable} to a \term{condition} if that
  354. \term{condition} is of the \term{type} designated by the associated
  355. \term{type specifier}.
  356. \term{Active} \term{handlers} are \term{established} by using
  357. \macref{handler-bind} (or an abstraction based on \macref{handler-bind},
  358. such as \macref{handler-case} or \macref{ignore-errors}).
  359. \term{Active} \term{handlers} can be \term{established} within the
  360. dynamic scope of other \term{active} \term{handlers}.
  361. At any point during program execution, there is a set of \term{active} \term{handlers}.
  362. When a \term{condition} is signaled, the \term{most recent} active \term{applicable handler}
  363. for that \term{condition} is selected from this set.
  364. Given a \term{condition}, the order of recentness of
  365. active \term{applicable handlers} is defined by the following two rules:
  366. \beginlist
  367. \itemitem{1.} Each handler in a set of active handlers $H\sub 1$ is
  368. more recent than every handler in a set $H\sub 2$ if the
  369. handlers in $H\sub 2$ were active when the handlers in $H\sub 1$ were
  370. established.
  371. \itemitem{2.} Let $h\sub 1$ and $h\sub 2$ be two applicable active
  372. handlers established by the same \term{form}. Then $h\sub 1$ is
  373. more recent than $h\sub 2$ if $h\sub 1$ was defined to the left of
  374. $h\sub 2$ in the \term{form} that established them.
  375. \endlist
  376. %!!! Barrett: This doesn't match my reading of CSv18, p12.
  377. % I believe contradicts p21,p22 of that document. It also differs from
  378. % previous paragraph (w/ item 2) and first paragraph under "signaling".
  379. Once a handler in a handler binding \term{form} (such as
  380. \macref{handler-bind} or \macref{handler-case}) has been selected, all
  381. handlers in that \term{form} become inactive for
  382. the remainder of the signaling process.
  383. %--------------------------------------
  384. While the selected \term{handler} runs, no other \term{handler} established
  385. by that \term{form} is active. That is, if the \term{handler} declines,
  386. no other handler established by that \term{form} will be considered for possible invocation.
  387. %-----------------------------------------------------------------------------------------
  388. \Thenextfigure\ shows \term{operators} relating to
  389. the \term{handling} of \term{conditions}.
  390. \displaythree{Operators relating to handling conditions.}{
  391. handler-bind&handler-case&ignore-errors\cr
  392. }
  393. \beginsubsubsection{Signaling}
  394. \DefineSection{Signaling}
  395. When a \term{condition} is signaled, the most recent
  396. applicable \term{active} \term{handler} is invoked.
  397. Sometimes a handler will decline by simply returning
  398. without a transfer of control.
  399. In such cases, the next most recent applicable active handler is
  400. invoked.
  401. If there are no applicable handlers for a \term{condition} that
  402. has been signaled, or if all applicable handlers decline, the
  403. \term{condition} is unhandled.
  404. The functions \funref{cerror} and \funref{error} invoke the
  405. interactive \term{condition} handler (the debugger) rather than
  406. return if the \term{condition} being signaled, regardless of
  407. its \term{type}, is unhandled. In contrast, \funref{signal}
  408. returns \nil\ if the \term{condition} being signaled,
  409. regardless of its \term{type}, is unhandled.
  410. \Thevariable{*break-on-signals*} can be used to cause the
  411. debugger to be entered before the signaling process begins.
  412. \Thenextfigure\ shows \term{defined names} relating to
  413. the \term{signaling} of \term{conditions}.
  414. \displaythree{Defined names relating to signaling conditions.}{
  415. *break-on-signals*&error&warn\cr
  416. cerror&signal&\cr
  417. }
  418. \beginsubsubsubsection{Resignaling a Condition}
  419. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  420. During the \term{dynamic extent} of the \term{signaling} process for
  421. a particular \term{condition} \term{object},
  422. \funref{signaling} the same \term{condition} \term{object} again
  423. is permitted if and only if the \term{situation} represented in both
  424. cases are the same.
  425. For example, a \term{handler} might legitimately \term{signal}
  426. the \term{condition} \term{object} that is its \term{argument}
  427. in order to allow outer \term{handlers} first opportunity to \term{handle}
  428. the condition. (Such a \term{handlers} is sometimes called a ``default handler.'')
  429. This action is permitted because the \term{situation} which the second
  430. \term{signaling} process is addressing is really the same \term{situation}.
  431. On the other hand, in an \term{implementation} that implemented asynchronous
  432. keyboard events by interrupting the user process with a call to \funref{signal},
  433. it would not be permissible for two distinct asynchronous keyboard events
  434. to \term{signal} \term{identical} \term{condition} \term{objects}
  435. at the same time for different
  436. %% Per X3J13 (at request of Gadbois). -kmp 5-Oct-93
  437. %the
  438. situations.
  439. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  440. \endsubsubsubsection%{Resignaling a Condition}
  441. \endsubsubsection%{Signaling}
  442. \beginsubsubsection{Restarts}
  443. \DefineSection{Restarts}
  444. %!!! Barrett: Not true. Debugger may permit arbitrary returning, depending on implementation.
  445. The interactive condition handler returns only through
  446. non-local transfer of control to specially defined \term{restarts}
  447. that can be set up either by the system or by user code. Transferring
  448. control to a restart is called ``invoking'' the restart. Like
  449. handlers, active \term{restarts} are \term{established}
  450. dynamically, and
  451. only active \term{restarts}
  452. can be invoked. An active
  453. \term{restart} can be invoked by the user from
  454. the debugger or by a program by using \funref{invoke-restart}.
  455. %!!! Barrett: :TEST predicate also affects applicability.
  456. A \term{restart} contains a
  457. \term{function} to be \term{called} when the \term{restart} is
  458. invoked, an optional name that can be used to find or invoke the
  459. \term{restart}, and
  460. an optional set of interaction information for the debugger to use to
  461. enable the user to manually invoke a \term{restart}.
  462. % some optional information that allows the debugger
  463. % to manage the interactive selection of the \term{restart} in
  464. % situations where program handlers cannot select one.
  465. The name of a \term{restart} is
  466. used by \funref{invoke-restart}. \term{Restarts} that can be invoked
  467. only within the debugger do not need names.
  468. %Useless information - terms unnamed and anonymous are never used.
  469. %\term{Restart} names provide a means
  470. %to access program interfaces
  471. %such as
  472. %\funref{find-restart} and \funref{invoke-restart}.
  473. %\term{Restarts} named
  474. %\nil\ are called ``unnamed'' or ``anonymous''
  475. %\term{restarts}. Named \term{restarts}
  476. %can be used in both
  477. %interactive and non-interactive situations, but unnamed
  478. %\term{restarts} are typically useful only in interactive situations.
  479. \term{Restarts} can be established by using \macref{restart-bind},
  480. \macref{restart-case}, and \macref{with-simple-restart}.
  481. A \term{restart} function can itself invoke any other \term{restart}
  482. that was active at the time of establishment of the \term{restart}
  483. of which the \term{function} is part.
  484. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  485. \issue{JUN90-TRIVIAL-ISSUES:14}
  486. The \term{restarts} \term{established} by
  487. a \macref{restart-bind} \term{form},
  488. a \macref{restart-case} \term{form},
  489. or a \macref{with-simple-restart} \term{form}
  490. have \term{dynamic extent}
  491. which extends for the duration of that \term{form}'s execution.
  492. \endissue{JUN90-TRIVIAL-ISSUES:14}
  493. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  494. \term{Restarts} of the same name can be ordered from least recent to
  495. most recent according to the following two rules:
  496. \beginlist
  497. \itemitem{1.} Each \term{restart} in a set of active restarts
  498. $R\sub 1$ is more recent than every \term{restart} in a
  499. set $R\sub 2$ if the \term{restarts}
  500. in $R\sub 2$ were active when the \term{restarts} in $R\sub 1$ were
  501. established.
  502. \itemitem{2.} Let $r\sub 1$ and $r\sub 2$ be two active \term{restarts} with
  503. the same name established by the same \term{form}. Then $r\sub 1$ is
  504. more recent than $r\sub 2$ if $r\sub 1$ was defined to the
  505. left of $r\sub 2$ in the \term{form} that established them.
  506. \endlist
  507. If a \term{restart} is invoked but does not transfer control,
  508. the values resulting from the \term{restart} function are
  509. returned by the function that invoked the restart, either
  510. \funref{invoke-restart} or \funref{invoke-restart-interactively}.
  511. %!!! Barrett: There are other functions that invoke restarts that we built
  512. % on these two; i.e., muffle-warning, etc.
  513. \beginsubsubsubsection{Interactive Use of Restarts}
  514. %%KMP replaced
  515. %Interaction information comprises two \term{functions}, called the
  516. %\kwd{report} function and the \kwd{interactive}
  517. %function. The \kwd{report} function is used to print a
  518. %description of the \term{restart} and takes a
  519. %\term{stream} as an argument. The
  520. %\kwd{interactive} function is used to produce a list of
  521. %arguments for the \term{restart} function if that
  522. %\term{restart} is invoked; the
  523. %\kwd{interactive} function takes no arguments.
  524. %
  525. %
  526. %When the debugger is entered, the set of active \term{restarts}
  527. %is presented to the user. If an active \term{restart} has interaction
  528. %information, the \kwd{report} function is used to print a
  529. %description of the \term{restart}. If the
  530. %\term{restart} is invoked (in an
  531. %\term{implementation-dependent} manner), the \kwd{interactive} function
  532. %is invoked to produce a list of arguments to which the \term{restart}
  533. %function is applied as if with \funref{apply}. If an active
  534. %\term{restart} does not have a \kwd{report}
  535. %function and a description
  536. %of the \term{restart} is printed, the description is
  537. %\term{implementation-dependent}. If an active \term{restart} does have not an
  538. %\kwd{interactive} function and the \term{restart} is invoked
  539. %interactively, the \term{restart}
  540. %function is invoked with no arguments.
  541. %\macref{restart-bind} and \macref{restart-case} supply
  542. %defaults for interaction information.
  543. %If a \term{restart}
  544. %is invoked from
  545. %within the debugger and the \term{restart}
  546. %function simply returns,
  547. %the consequences are unspecified.
  548. For interactive handling, two pieces of information are needed
  549. from a \term{restart}: a report function and an interactive function.
  550. The report function
  551. %which can be specified using the
  552. %\kwd{report-function}
  553. % keyword in
  554. %\macref{restart-bind} or the
  555. %\kwd{report} keyword in \macref{restart-case},
  556. is used by a program such as the debugger to
  557. present a description of the action the \term{restart} will take.
  558. The report function is specified and established by the
  559. \kwd{report-function} keyword to
  560. \macref{restart-bind} or the
  561. \kwd{report} keyword to \macref{restart-case}.
  562. %The
  563. % report function is a function of one argument, a stream on which
  564. % the output is to be done. If no report function is specified by
  565. % the user, the restart will be reported in an \term{implementation-dependent}
  566. % way.
  567. The interactive function, which can be specified using the
  568. \kwd{interactive-function} keyword to
  569. \macref{restart-bind} or \kwd{interactive} keyword
  570. to \macref{restart-case}, is used when the \term{restart}
  571. is invoked
  572. interactively, such as from the debugger, to produce a suitable
  573. list of arguments.
  574. %The function takes no arguments, and may
  575. % prompt interactively on *QUERY-IO* if necessary. The result
  576. % should be a list of arguments suitable for use in the expression
  577. % (APPLY #'INVOKE-RESTART <restart> <arguments>).
  578. % If no interactive function is specified by the user, the argument
  579. % list NIL will be assumed.
  580. \funref{invoke-restart} invokes the most recently \term{established}
  581. %!!! Barrett: "active" -- :TEST could inhibit activation.
  582. \term{restart} whose
  583. name is the same as the first argument to \funref{invoke-restart}.
  584. If a \term{restart} is invoked interactively by the debugger and does
  585. not transfer control but rather returns values, the precise
  586. action of the debugger on those values is \term{implementation-defined}.
  587. %!!! Barrett: This doesn't talk about supplying restart objects to INVOKE-RESTART.
  588. \endsubsubsubsection%{Interactive Use of Restarts}
  589. \beginsubsubsubsection{Interfaces to Restarts}
  590. \DefineSection{InterfacesToRestarts}
  591. %%KMP replaced
  592. %It is possible to define a functional interface that hides the use of
  593. %\funref{invoke-restart}. The functions \funref{abort},
  594. %\funref{continue}, \funref{muffle-warning}, \funref{store-value},
  595. %and \funref{use-value} are such interfaces.
  596. Some \term{restarts} have functional interfaces,
  597. %either for syntactic
  598. % convenience or to de-emphasize the use of restarts in their
  599. % implementation.
  600. such as \funref{abort}, \funref{continue},
  601. \funref{muffle-warning}, \funref{store-value}, and
  602. \funref{use-value}.
  603. They are ordinary functions that use
  604. \funref{find-restart} and \funref{invoke-restart} internally,
  605. that have the same name as the \term{restarts} they manipulate,
  606. and that are provided simply for notational convenience.
  607. \Thenextfigure\ shows \term{defined names} relating to
  608. \term{restarts}.
  609. \displaythree{Defined names relating to restarts.}{
  610. abort&invoke-restart-interactively&store-value\cr
  611. compute-restarts&muffle-warning&use-value\cr
  612. continue&restart-bind&with-simple-restart\cr
  613. find-restart&restart-case&\cr
  614. invoke-restart&restart-name&\cr
  615. }
  616. \endsubsubsubsection%{Interfaces to Restarts}
  617. \beginsubsubsubsection{Restart Tests}
  618. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  619. Each \term{restart} has an associated test, which is a function of one
  620. argument (a \term{condition} or \nil) which returns \term{true} if the \term{restart}
  621. should be visible in the current \term{situation}. This test is created by
  622. the \kwd{test-function} option to \macref{restart-bind} or
  623. the \kwd{test} option to \macref{restart-case}.
  624. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  625. \endsubsubsubsection%{Restart Tests}
  626. \beginsubsubsubsection{Associating a Restart with a Condition}
  627. \DefineSection{AssocRestartWithCond}
  628. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  629. A \term{restart} can be ``associated with'' a \term{condition} explicitly
  630. by \macref{with-condition-restarts}, or implicitly by \macref{restart-case}.
  631. Such an assocation has \term{dynamic extent}.
  632. A single \term{restart} may be associated with several \term{conditions}
  633. at the same time.
  634. A single \term{condition} may have several associated \term{restarts}
  635. at the same time.
  636. Active restarts associated with a particular \term{condition} can be detected
  637. by \term{calling} a \term{function} such as \funref{find-restart}, supplying
  638. that \term{condition} as the \param{condition} \term{argument}.
  639. Active restarts can also be detected without regard to any associated
  640. \term{condition} by calling such a function without a \param{condition} \term{argument},
  641. or by supplying a value of \nil\ for such an \term{argument}.
  642. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  643. \endsubsubsubsection%{Associating a Restart with a Condition}
  644. \endsubsubsection%{Restarts}
  645. \endSubsection%{Signaling and Handling Conditions}
  646. \goodbreak
  647. \beginSubsection{Assertions}
  648. Conditional signaling of \term{conditions}
  649. based on such things as key match, form evaluation,
  650. and \term{type} are handled by assertion \term{operators}.
  651. \Thenextfigure\ shows \term{operators} relating to assertions.
  652. \displaythree{Operators relating to assertions.}{
  653. assert&check-type&ecase\cr
  654. ccase&ctypecase&etypecase\cr
  655. }
  656. \endSubsection%{Assertions}
  657. % Date: Tue, 4 Jun 91 10:39:28 EDT
  658. % From: kab@chestnut.com (Kim Barrett)
  659. % To: mueller@sumex-aim.stanford.edu
  660. % Cc: common-lisp@mcc.com
  661. % Message-Id: <9106041439.AA08564@chestnut.com>
  662. % In-Reply-To: <2884982915-12705048@KSL-EXP-30>
  663. % Subject: CLEH restarts...
  664. %
  665. % [...]
  666. % The rules for determining whether a (visible) restart is active are:
  667. %
  668. % 1. If the test function for the restart returns false when applied to the
  669. % condition argument (which may be NIL), then the restart is inactive.
  670. %
  671. % 2. If testing for applicability to a specific condition (the condition argument
  672. % is actually a condition object), then either
  673. % a. The restart is associated with the specified condition.
  674. % b. The restart is not associated with some other condition object.
  675. % [This case was accidentally left out of the Version 2 proposal.]
  676. % or the restart is inactive.
  677. %
  678. % 3. If neither of (1) and (2) indicate the restart to be inactive, then it is
  679. % active.
  680. % [...]
  681. \beginsubsection{Notes about the Condition System's Background}
  682. For a background reference to the abstract concepts detailed in this
  683. section, see \CondSysPaper. The details of that paper are not binding on
  684. this document, but may be helpful in establishing a conceptual basis for
  685. understanding this material.
  686. \endsubsection%{Notes about the Condition System's Background}