dict-conditions.tex 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080
  1. % -*- Mode: TeX -*-
  2. % Conditions
  3. % Conditions
  4. % Signaling
  5. % Debugger
  6. % Handling
  7. % Condition Types
  8. % Condition Type Definition
  9. % Condition Instantiation
  10. % Condition Types/Accessors
  11. % Restarts
  12. % PreDefined Restarts
  13. %%% ========== CONDITION
  14. \begincom{condition}\ftype{Condition Type}
  15. \issue{CONDITION-RESTARTS:BUGGY}
  16. \reviewer{Barrett: I think CONDITION-RESTARTS is not fully integrated.}
  17. \endissue{CONDITION-RESTARTS:BUGGY}
  18. %!!! Barrett notes of the condition types:
  19. % There is little discussion in this descriptions of what the values
  20. % of the initargs ought to be. For example, package-error permits name
  21. % or package object.
  22. \label Class Precedence List::
  23. \typeref{condition},
  24. \typeref{t}
  25. \label Description::
  26. All types of \term{conditions}, whether error or
  27. non-error, must inherit from this \term{type}.
  28. \issue{CLOS-CONDITIONS-AGAIN:ALLOW-SUBSET}
  29. \issue{CLOS-CONDITIONS:INTEGRATE}
  30. %%As noted by Symbolics, these just repeat the obvious:
  31. %All types of \term{conditions} are \term{classes}.
  32. %All \term{condition} \term{objects} are \term{generalized instances} of one
  33. %or more \term{classes}.
  34. % Barmar thinks the next statement is unnecessary and incomplete.
  35. % I think there's also a later cleanup issue which undoes it. Work on this more. -kmp
  36. % Barrett also asks what about SLOT-VALUE and its setf.
  37. %% Removed. This is explained better below. -kmp 1-Oct-91
  38. % \term{Slots} in \term{condition} \term{objects} can be accessed
  39. % using \macref{with-slots}.
  40. \endissue{CLOS-CONDITIONS:INTEGRATE}
  41. \endissue{CLOS-CONDITIONS-AGAIN:ALLOW-SUBSET}
  42. % %!!! Barrett points out that these look a little lonely all by themselves. -kmp 23-Oct-90
  43. % % (Well, they used to be somewhere different, so maybe they are not so
  44. % % lonely now, but I'll leave the comment and think more about it later. -kmp 13-Nov-90)
  45. % %!!! Barrett thinks this "disjointness" is probably false and in any case uninteresting.
  46. %% Finally commented out for Barrett. -kmp 2-Feb-92
  47. % The \term{types} \typeref{simple-condition}, \typeref{warning},
  48. % and \typeref{serious-condition} are \term{pairwise} \term{disjoint}.
  49. No additional \term{subtype} relationships among the specified \subtypesof{condition}
  50. are allowed, except when explicitly mentioned in the text; however
  51. implementations are permitted to introduce additional \term{types}
  52. and one of these \term{types} can be a \term{subtype} of any
  53. number of the \subtypesof{condition}.
  54. \issue{CONDITION-SLOTS:HIDDEN}
  55. Whether a user-defined \term{condition} \term{type} has \term{slots}
  56. that are accessible by \term{with-slots} is \term{implementation-dependent}.
  57. Furthermore, even in an \term{implementation}
  58. in which user-defined \term{condition} \term{types} would have \term{slots},
  59. it is \term{implementation-dependent} whether any \term{condition}
  60. \term{types} defined in this document have such \term{slots} or,
  61. if they do, what their \term{names} might be;
  62. only the reader functions documented by this specification may be relied
  63. upon by portable code.
  64. \endissue{CONDITION-SLOTS:HIDDEN}
  65. \issue{CLOS-CONDITIONS-AGAIN:ALLOW-SUBSET}
  66. \term{Conforming code} must observe the following restrictions related to
  67. \term{conditions}:
  68. \beginlist
  69. \itemitem{\bull}
  70. \macref{define-condition}, not \macref{defclass}, must be used
  71. to define new \term{condition} \term{types}.
  72. \itemitem{\bull}
  73. \macref{make-condition}, not \funref{make-instance}, must be used to
  74. create \term{condition} \term{objects} explicitly.
  75. \itemitem{\bull}
  76. The \kwd{report} option of \macref{define-condition}, not \macref{defmethod}
  77. for \funref{print-object}, must be used to define a condition reporter.
  78. \itemitem{\bull}
  79. \funref{slot-value}, \funref{slot-boundp}, \funref{slot-makunbound},
  80. and \macref{with-slots} must not be used on \term{condition} \term{objects}.
  81. Instead, the appropriate accessor functions (defined by \macref{define-condition})
  82. should be used.
  83. \endlist
  84. \endissue{CLOS-CONDITIONS-AGAIN:ALLOW-SUBSET}
  85. \endcom%{condition}\ftype{Condition Type}
  86. \begincom{warning}\ftype{Condition Type}
  87. \label Class Precedence List::
  88. \typeref{warning},
  89. \typeref{condition},
  90. \typeref{t}
  91. \label Description::
  92. \Thetype{warning} consists of all types of warnings.
  93. \label See Also::
  94. \typeref{style-warning}
  95. \endcom%{warning}\ftype{Condition Type}
  96. \issue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  97. \begincom{style-warning}\ftype{Condition Type}
  98. \label Class Precedence List::
  99. \typeref{style-warning},
  100. \typeref{warning},
  101. \typeref{condition},
  102. \typeref{t}
  103. \label Description::
  104. \Thetype{style-warning} includes those \term{conditions}
  105. that represent \term{situations} involving \term{code}
  106. that is \term{conforming code} but that is nevertheless
  107. considered to be faulty or substandard.
  108. \label See Also::
  109. \funref{muffle-warning}
  110. \label Notes::
  111. An \term{implementation} might signal such a \term{condition}
  112. if it encounters \term{code}
  113. that uses deprecated features
  114. or that appears unaesthetic or inefficient.
  115. An `unused variable' warning must be \oftype{style-warning}.
  116. In general, the question of whether \term{code} is faulty or substandard
  117. is a subjective decision to be made by the facility processing that \term{code}.
  118. The intent is that whenever such a facility wishes to complain about
  119. \term{code} on such subjective grounds, it should use this
  120. \term{condition} \term{type} so that any clients who wish to redirect or
  121. muffle superfluous warnings can do so without risking that they will be
  122. redirecting or muffling other, more serious warnings.
  123. \endcom%{style-warning}\ftype{Condition Type}
  124. \endissue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  125. \begincom{serious-condition}\ftype{Condition Type}
  126. \label Class Precedence List::
  127. \typeref{serious-condition},
  128. \typeref{condition},
  129. \typeref{t}
  130. \label Description::
  131. All \term{conditions} serious enough to require interactive intervention
  132. if not handled should inherit from \thetype{serious-condition}.
  133. This condition type is provided
  134. %for terminological convenience.
  135. primarily so that it may be included as
  136. a \term{superclass} of other \term{condition} \term{types};
  137. it is not intended to be signaled directly.
  138. \label Notes::
  139. % It is
  140. % conventional to use \funref{error} (or something built on
  141. % \funref{error}) to \term{signal} \term{conditions} that are \oftype{serious-condition},
  142. % and to use \funref{signal} to \term{signal} \term{conditions}
  143. % that are not of this \term{type}.
  144. Signaling a \term{serious condition} does not itself force entry into
  145. the debugger. However, except in the unusual situation where the
  146. programmer can assure that no harm will come from failing to
  147. \term{handle} a \term{serious condition}, such a \term{condition} is
  148. usually signaled with \funref{error} rather than \funref{signal} in
  149. order to assure that the program does not continue without
  150. \term{handling} the \term{condition}. (And conversely, it is
  151. conventional to use \funref{signal} rather than \funref{error} to signal
  152. conditions which are not \term{serious conditions}, since normally the
  153. failure to handle a non-serious condition is not reason enough for the
  154. debugger to be entered.)
  155. \endcom%{serious-condition}\ftype{Condition Type}
  156. \begincom{error}\ftype{Condition Type}
  157. \label Class Precedence List::
  158. \typeref{error},
  159. \typeref{serious-condition},
  160. \typeref{condition},
  161. \typeref{t}
  162. \label Description::
  163. \Thetype{error} consists of all \term{conditions} that represent \term{errors}.
  164. \endcom%{error}\ftype{Condition Type}
  165. \begincom{cell-error}\ftype{Condition Type}
  166. \label Class Precedence List::
  167. \typeref{cell-error},
  168. \typeref{error},
  169. \typeref{serious-condition},
  170. \typeref{condition},
  171. \typeref{t}
  172. \label Description::
  173. \Thetype{cell-error} consists of error conditions that occur during
  174. a location \term{access}. The name of the offending cell is initialized by
  175. \theinitkeyarg{name} to \funref{make-condition},
  176. and is \term{accessed} by \thefunction{cell-error-name}.
  177. \label See Also::
  178. \funref{cell-error-name}
  179. \endcom%{cell-error}\ftype{Condition Type}
  180. %%% ========== CELL-ERROR-NAME
  181. \begincom{cell-error-name}\ftype{Function}
  182. \issue{ACCESS-ERROR-NAME}
  183. \label Syntax::
  184. \DefunWithValues cell-error-name {condition} {name}
  185. \label Arguments and Values::
  186. \param{condition}---a \term{condition} \oftype{cell-error}.
  187. \param{name}---an \term{object}.
  188. \label Description::
  189. Returns the \term{name} of the offending cell involved in the \term{situation}
  190. represented by \param{condition}.
  191. The nature of the result depends on the specific \term{type} of \param{condition}.
  192. For example,
  193. if the \param{condition} is \oftype{unbound-variable}, the result is
  194. the \term{name} of the \term{unbound variable} which was being \term{accessed},
  195. if the \param{condition} is \oftype{undefined-function}, this is
  196. the \term{name} of the \term{undefined function} which was being \term{accessed},
  197. and if the \param{condition} is \oftype{unbound-slot}, this is
  198. the \term{name} of the \term{slot} which was being \term{accessed}.
  199. \label Examples:\None.
  200. \label Affected By:\None.
  201. \label Exceptional Situations:\None.
  202. \label See Also::
  203. \typeref{cell-error},
  204. \typeref{unbound-slot},
  205. \typeref{unbound-variable},
  206. \typeref{undefined-function},
  207. {\secref\ConditionSystemConcepts}
  208. \label Notes:\None.
  209. %Barmar: This should be ``consequences are unspecified.''
  210. %Shouldn't be needed anyway--we don't provide an operator.
  211. %It is an error to use \macref{setf} with \funref{cell-error-name}.
  212. \endissue{ACCESS-ERROR-NAME}
  213. \endcom
  214. \begincom{parse-error}\ftype{Condition Type}
  215. \issue{PARSE-ERROR-STREAM:SPLIT-TYPES}
  216. \issue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  217. \issue{READER-ERROR:NEW-TYPE}
  218. \label Class Precedence List::
  219. \typeref{parse-error},
  220. \typeref{error},
  221. \typeref{serious-condition},
  222. \typeref{condition},
  223. \typeref{t}
  224. \label Description::
  225. \Thetype{parse-error} consists of
  226. error conditions that are related to parsing.
  227. \label See Also::
  228. \funref{parse-namestring},
  229. \funref{reader-error}
  230. \endissue{READER-ERROR:NEW-TYPE}
  231. \endissue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  232. \endissue{PARSE-ERROR-STREAM:SPLIT-TYPES}
  233. \endcom%{parse-error}\ftype{Condition Type}
  234. \begincom{storage-condition}\ftype{Condition Type}
  235. \label Class Precedence List::
  236. \typeref{storage-condition},
  237. \typeref{serious-condition},
  238. \typeref{condition},
  239. \typeref{t}
  240. \label Description::
  241. \Thetype{storage-condition} consists of serious conditions that
  242. relate to problems with memory management that are potentially due to
  243. \term{implementation-dependent} limits rather than semantic errors
  244. in \term{conforming programs}, and that typically warrant entry to the
  245. debugger if not handled. Depending on the details of the \term{implementation},
  246. these might include such problems as
  247. stack overflow,
  248. memory region overflow,
  249. and
  250. storage exhausted.
  251. \label Notes::
  252. While some \clisp\ operations might signal \term{storage-condition}
  253. because they are defined to create \term{objects},
  254. it is unspecified whether operations that are not defined to create
  255. \term{objects} create them anyway
  256. and so might also signal \typeref{storage-condition}.
  257. Likewise, the evaluator itself might create \term{objects}
  258. and so might signal \typeref{storage-condition}.
  259. (The natural assumption might be that such
  260. \term{object} creation is naturally inefficient,
  261. but even that is \term{implementation-dependent}.)
  262. In general, the entire question of how storage allocation is done is
  263. \term{implementation-dependent},
  264. and so any operation might signal \typeref{storage-condition} at any time.
  265. Because such a \term{condition} is indicative of a limitation
  266. of the \term{implementation}
  267. or of the \term{image}
  268. rather than an error in a \term{program},
  269. \term{objects} \oftype{storage-condition} are not \oftype{error}.
  270. \endcom%{storage-condition}\ftype{Condition Type}
  271. %-------------------- Signaling --------------------
  272. %%% ========== ASSERT
  273. \begincom{assert}\ftype{Macro}
  274. \label Syntax::
  275. \DefmacWithValuesNewline assert
  276. {test-form \brac{\paren{\starparam{place}}
  277. \brac{datum-form
  278. \starparam{argument-form}}}}
  279. {\nil}
  280. \label Arguments and Values::
  281. \param{test-form}---a \term{form}; always evaluated.
  282. \param{place}---a \term{place}; evaluated if an error is signaled.
  283. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  284. \param{datum-form}---a \term{form} that evaluates to a \param{datum}.
  285. Evaluated each time an error is to be signaled,
  286. or not at all if no error is to be signaled.
  287. \param{argument-form}---a \term{form} that evaluates to an \param{argument}.
  288. Evaluated each time an error is to be signaled,
  289. or not at all if no error is to be signaled.
  290. \issue{ASSERT-ERROR-TYPE:ERROR}
  291. \param{datum}, \param{arguments}---\term{designators} for a \term{condition}
  292. of default type \typeref{error}. (These \term{designators} are the
  293. result of evaluating \param{datum-form} and each of the \param{argument-forms}.)
  294. \endissue{ASSERT-ERROR-TYPE:ERROR}
  295. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  296. \label Description::
  297. \funref{assert} assures that \param{test-form} evaluates to \term{true}.
  298. If \param{test-form} evaluates to \term{false}, \macref{assert} signals a
  299. \term{correctable} \term{error} (denoted by \param{datum} and \param{arguments}).
  300. Continuing from this error using \therestart{continue} makes it possible
  301. for the user to alter the values of the \param{places} before
  302. \macref{assert} evaluates \param{test-form} again.
  303. If the value of \param{test-form} is \term{non-nil},
  304. \funref{assert} returns \nil.
  305. The \param{places} are \term{generalized references} to data
  306. upon which \param{test-form} depends,
  307. whose values can be changed by the user in attempting to correct the error.
  308. \term{Subforms} of each \param{place} are only evaluated if an error is signaled,
  309. and might be re-evaluated if the error is re-signaled (after continuing without
  310. actually fixing the problem).
  311. \issue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  312. The order of evaluation of the \param{places} is not specified;
  313. \seesection\GenRefSubFormEval.\idxtext{order of evaluation}\idxtext{evaluation order}
  314. \endissue{PUSH-EVALUATION-ORDER:FIRST-ITEM}
  315. \issue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  316. If a \param{place} \term{form} is supplied that produces more values than there
  317. are store variables, the extra values are ignored. If the supplied
  318. \term{form} produces fewer values than there are store variables,
  319. the missing values are set to \nil.
  320. \endissue{SETF-MULTIPLE-STORE-VARIABLES:ALLOW}
  321. \label Examples::
  322. \code
  323. (setq x (make-array '(3 5) :initial-element 3))
  324. \EV #2A((3 3 3 3 3) (3 3 3 3 3) (3 3 3 3 3))
  325. (setq y (make-array '(3 5) :initial-element 7))
  326. \EV #2A((7 7 7 7 7) (7 7 7 7 7) (7 7 7 7 7))
  327. (defun matrix-multiply (a b)
  328. (let ((*print-array* nil))
  329. (assert (and (= (array-rank a) (array-rank b) 2)
  330. (= (array-dimension a 1) (array-dimension b 0)))
  331. (a b)
  332. "Cannot multiply ~S by ~S." a b)
  333. (really-matrix-multiply a b))) \EV MATRIX-MULTIPLY
  334. (matrix-multiply x y)
  335. \OUT Correctable error in MATRIX-MULTIPLY:
  336. \OUT Cannot multiply #<ARRAY ...> by #<ARRAY ...>.
  337. \OUT Restart options:
  338. \OUT 1: You will be prompted for one or more new values.
  339. \OUT 2: Top level.
  340. \OUT Debug> \IN{:continue 1}
  341. \OUT Value for A: \IN{x}
  342. \OUT Value for B: \IN{(make-array '(5 3) :initial-element 6)}
  343. \EV #2A((54 54 54 54 54)
  344. (54 54 54 54 54)
  345. (54 54 54 54 54)
  346. (54 54 54 54 54)
  347. (54 54 54 54 54))
  348. \endcode
  349. \code
  350. (defun double-safely (x) (assert (numberp x) (x)) (+ x x))
  351. (double-safely 4)
  352. \EV 8
  353. (double-safely t)
  354. \OUT Correctable error in DOUBLE-SAFELY: The value of (NUMBERP X) must be non-NIL.
  355. \OUT Restart options:
  356. \OUT 1: You will be prompted for one or more new values.
  357. \OUT 2: Top level.
  358. \OUT Debug> \IN{:continue 1}
  359. \OUT Value for X: \IN{7}
  360. \EV 14
  361. \endcode
  362. \label Affected By::
  363. \varref{*break-on-signals*}
  364. % Barrett thinks that \varref{*debug-io*} and others don't belong here because
  365. % debugger might not be reached, and anyway it is a full turing machine and might
  366. % depend on virtually anything.
  367. The set of active \term{condition handlers}.
  368. \label Exceptional Situations:\None.
  369. %% Barrett says, and I agree, that this isn't an exceptional situation.
  370. %% Anyway, it's said above. -kmp 2-Sep-91
  371. % If the value of \param{test-form} is \nil,
  372. % \macref{assert} signals a user-specified \term{condition},
  373. % which defaults to \typeref{simple-error}.
  374. \label See Also::
  375. \funref{check-type}, \funref{error}, {\secref\GeneralizedReference}
  376. \label Notes::
  377. The debugger need not include the \param{test-form} in the error message,
  378. and the \param{places} should not be included in the message, but they
  379. should be made available for the user's perusal. If the user gives the
  380. ``continue'' command, the values of any of the references can be altered.
  381. The details of this depend on the implementation's style of user interface.
  382. \endcom
  383. %%% ========== ERROR
  384. \begincom{error}\ftype{Function}
  385. \label Syntax::
  386. \DefunNoReturn error {datum {\rest} arguments}
  387. \label Arguments and Values::
  388. \param{datum}, \param{arguments}---\term{designators} for a \term{condition}
  389. of default type \typeref{simple-error}.
  390. \label Description::
  391. \funref{error} effectively invokes \funref{signal} on the denoted \term{condition}.
  392. If the \term{condition} is not handled, \f{(invoke-debugger \i{condition})} is done.
  393. As a consequence of calling \funref{invoke-debugger}, \funref{error}
  394. cannot directly return; the only exit from \funref{error}
  395. can come by non-local transfer of control in a handler or by use of
  396. an interactive debugging command.
  397. \label Examples::
  398. \code
  399. (defun factorial (x)
  400. (cond ((or (not (typep x 'integer)) (minusp x))
  401. (error "~S is not a valid argument to FACTORIAL." x))
  402. ((zerop x) 1)
  403. (t (* x (factorial (- x 1))))))
  404. \EV FACTORIAL
  405. (factorial 20)
  406. \EV 2432902008176640000
  407. (factorial -1)
  408. \OUT Error: -1 is not a valid argument to FACTORIAL.
  409. \OUT To continue, type :CONTINUE followed by an option number:
  410. \OUT 1: Return to Lisp Toplevel.
  411. \OUT Debug>
  412. \endcode
  413. \code
  414. (setq a 'fred)
  415. \EV FRED
  416. (if (numberp a) (1+ a) (error "~S is not a number." A))
  417. \OUT Error: FRED is not a number.
  418. \OUT To continue, type :CONTINUE followed by an option number:
  419. \OUT 1: Return to Lisp Toplevel.
  420. \OUT Debug> \IN{:Continue 1}
  421. \OUT Return to Lisp Toplevel.
  422. (define-condition not-a-number (error)
  423. ((argument :reader not-a-number-argument :initarg :argument))
  424. (:report (lambda (condition stream)
  425. (format stream "~S is not a number."
  426. (not-a-number-argument condition)))))
  427. \EV NOT-A-NUMBER
  428. (if (numberp a) (1+ a) (error 'not-a-number :argument a))
  429. \OUT Error: FRED is not a number.
  430. \OUT To continue, type :CONTINUE followed by an option number:
  431. \OUT 1: Return to Lisp Toplevel.
  432. \OUT Debug> \IN{:Continue 1}
  433. \OUT Return to Lisp Toplevel.
  434. \endcode
  435. \label Side Effects::
  436. \term{Handlers} for the specified condition, if any, are invoked
  437. and might have side effects.
  438. Program execution might stop, and the debugger might be entered.
  439. \label Affected By::
  440. Existing handler bindings.
  441. \varref{*break-on-signals*}
  442. %\varref{*debug-io*}.
  443. \label Exceptional Situations:\None.
  444. %% Not exceptional.
  445. % The reason for using \funref{error} is to signal a \term{condition},
  446. % the exact nature of which is specified by the arguments; however,
  447. % that situation is not considered exceptional.
  448. \Checktypes{\param{datum} and \param{arguments}}{\term{designators} for a \term{condition}}
  449. \label See Also::
  450. \funref{cerror}, \funref{signal}, \funref{format},
  451. \macref{ignore-errors}, \varref{*break-on-signals*},
  452. \macref{handler-bind}, {\secref\ConditionSystemConcepts}
  453. \label Notes::
  454. Some implementations may provide debugger
  455. commands for interactively returning from individual stack frames.
  456. However, it should be possible for the programmer to feel confident
  457. about writing code like:
  458. \code
  459. (defun wargames:no-win-scenario ()
  460. (if (error "pushing the button would be stupid."))
  461. (push-the-button))
  462. \endcode
  463. In this scenario, there should be no chance that
  464. \funref{error} will return
  465. and the button will get pushed.
  466. While the meaning of this program is clear and it might be proven `safe'
  467. by a formal theorem prover, such a proof is no guarantee that the
  468. program is safe to execute. Compilers have been known to have bugs,
  469. computers to have signal glitches, and human beings to manually
  470. intervene in ways that are not always possible to predict. Those kinds
  471. of errors, while beyond the scope of the condition system to formally
  472. model, are not beyond the scope of things that should seriously be
  473. considered when writing code that could have the kinds of sweeping
  474. effects hinted at by this example.
  475. \endcom
  476. %%% ========== CERROR
  477. \begincom{cerror}\ftype{Function}
  478. \label Syntax::
  479. \DefunWithValues cerror {continue-format-control datum {\rest} arguments} {\nil}
  480. \label Arguments and Values::
  481. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  482. \param{Continue-format-control}---a \term{format control}.
  483. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  484. \reviewer{Barmar: What is continue-format-control used for??}
  485. \param{datum}, \param{arguments}---\term{designators} for a \term{condition}
  486. of default type \typeref{simple-error}.
  487. \label Description::
  488. \funref{cerror} effectively invokes \funref{error} on the
  489. \term{condition} named by \param{datum}. As with any function that
  490. implicitly calls \funref{error}, if the \term{condition} is not handled,
  491. \f{(invoke-debugger \i{condition})} is executed. While signaling is going on,
  492. and while in the debugger if it is reached, it is possible to continue
  493. code execution (\ie to return from \funref{cerror}) using \therestart{continue}.
  494. % If the debugger is interactively instructed to continue,
  495. % the call to \funref{cerror} returns \nil.
  496. If \param{datum} is a \term{condition}, \param{arguments} can be supplied,
  497. but are used only in conjunction with the \param{continue-format-control}.
  498. \label Examples::
  499. %!!! I don't like the debugger typeout format here. -kmp 3-Sep-91
  500. \code
  501. (defun real-sqrt (n)
  502. (when (minusp n)
  503. (setq n (- n))
  504. (cerror "Return sqrt(~D) instead." "Tried to take sqrt(-~D)." n))
  505. (sqrt n))
  506. (real-sqrt 4)
  507. \EV 2.0
  508. (real-sqrt -9)
  509. \OUT Correctable error in REAL-SQRT: Tried to take sqrt(-9).
  510. \OUT Restart options:
  511. \OUT 1: Return sqrt(9) instead.
  512. \OUT 2: Top level.
  513. \OUT Debug> \IN{:continue 1}
  514. \EV 3.0
  515. (define-condition not-a-number (error)
  516. ((argument :reader not-a-number-argument :initarg :argument))
  517. (:report (lambda (condition stream)
  518. (format stream "~S is not a number."
  519. (not-a-number-argument condition)))))
  520. (defun assure-number (n)
  521. (loop (when (numberp n) (return n))
  522. (cerror "Enter a number."
  523. 'not-a-number :argument n)
  524. (format t "~&Type a number: ")
  525. (setq n (read))
  526. (fresh-line)))
  527. (assure-number 'a)
  528. \OUT Correctable error in ASSURE-NUMBER: A is not a number.
  529. \OUT Restart options:
  530. \OUT 1: Enter a number.
  531. \OUT 2: Top level.
  532. \OUT Debug> \IN{:continue 1}
  533. \OUT Type a number: \IN{1/2}
  534. \EV 1/2
  535. (defun assure-large-number (n)
  536. (loop (when (and (numberp n) (> n 73)) (return n))
  537. (cerror "Enter a number~:[~; a bit larger than ~D~]."
  538. "~*~A is not a large number."
  539. (numberp n) n)
  540. (format t "~&Type a large number: ")
  541. (setq n (read))
  542. (fresh-line)))
  543. (assure-large-number 10000)
  544. \EV 10000
  545. (assure-large-number 'a)
  546. \OUT Correctable error in ASSURE-LARGE-NUMBER: A is not a large number.
  547. \OUT Restart options:
  548. \OUT 1: Enter a number.
  549. \OUT 2: Top level.
  550. \OUT Debug> \IN{:continue 1}
  551. \OUT Type a large number: \IN{88}
  552. \EV 88
  553. (assure-large-number 37)
  554. \OUT Correctable error in ASSURE-LARGE-NUMBER: 37 is not a large number.
  555. \OUT Restart options:
  556. \OUT 1: Enter a number a bit larger than 37.
  557. \OUT 2: Top level.
  558. \OUT Debug> \IN{:continue 1}
  559. \OUT Type a large number: \IN{259}
  560. \EV 259
  561. (define-condition not-a-large-number (error)
  562. ((argument :reader not-a-large-number-argument :initarg :argument))
  563. (:report (lambda (condition stream)
  564. (format stream "~S is not a large number."
  565. (not-a-large-number-argument condition)))))
  566. (defun assure-large-number (n)
  567. (loop (when (and (numberp n) (> n 73)) (return n))
  568. (cerror "Enter a number~3*~:[~; a bit larger than ~*~D~]."
  569. 'not-a-large-number
  570. :argument n
  571. :ignore (numberp n)
  572. :ignore n
  573. :allow-other-keys t)
  574. (format t "~&Type a large number: ")
  575. (setq n (read))
  576. (fresh-line)))
  577. (assure-large-number 'a)
  578. \OUT Correctable error in ASSURE-LARGE-NUMBER: A is not a large number.
  579. \OUT Restart options:
  580. \OUT 1: Enter a number.
  581. \OUT 2: Top level.
  582. \OUT Debug> \IN{:continue 1}
  583. \OUT Type a large number: \IN{88}
  584. \EV 88
  585. (assure-large-number 37)
  586. \OUT Correctable error in ASSURE-LARGE-NUMBER: A is not a large number.
  587. \OUT Restart options:
  588. \OUT 1: Enter a number a bit larger than 37.
  589. \OUT 2: Top level.
  590. \OUT Debug> \IN{:continue 1}
  591. \OUT Type a large number: \IN{259}
  592. \EV 259
  593. \endcode
  594. \label Affected By::
  595. \varref{*break-on-signals*}.
  596. %\varref{*debug-io*}.
  597. Existing handler bindings.
  598. \label Exceptional Situations:\None.
  599. % The reason for using \funref{cerror} is to signal a \term{condition},
  600. % the exact nature of which is specified by the arguments.
  601. %!!! Was this saying anything useful??? -kmp 3-Sep-91
  602. % An error \oftype{type-error} is signaled if the \term{condition}
  603. % named by \param{datum} is not handled.
  604. \label See Also::
  605. \funref{error}, \funref{format}, \macref{handler-bind},
  606. \varref{*break-on-signals*}, \typeref{simple-type-error}
  607. \label Notes::
  608. If \param{datum} is a \term{condition} \term{type} rather than a
  609. \term{string}, the \funref{format} directive {\tt ~*} may be especially
  610. useful in the \param{continue-format-control} in order to ignore the
  611. \term{keywords} in the \term{initialization argument list}. For example:
  612. \code
  613. (cerror "enter a new value to replace ~*~s"
  614. 'not-a-number
  615. :argument a)
  616. \endcode
  617. \endcom
  618. %%% ========== CHECK-TYPE
  619. \begincom{check-type}\ftype{Macro}
  620. \label Syntax::
  621. \DefmacWithValues check-type {place typespec {\brac{\param{string}}}} {\nil}
  622. \label Arguments and Values::
  623. \param{place}---a \term{place}.
  624. \param{typespec}---a \term{type specifier}.
  625. \param{string}---a \term{string}; \eval. %!!! Really??
  626. \label Description::
  627. \funref{check-type} signals a \term{correctable} \term{error}
  628. \oftype{type-error} if the contents of \param{place} are not
  629. of the type \param{typespec}.
  630. \macref{check-type} can return only if \therestart{store-value} is invoked,
  631. either explicitly from a handler
  632. or implicitly as one of the options offered by the debugger.
  633. If \therestart{store-value} is invoked,
  634. \macref{check-type} stores the new value
  635. that is the argument to the \term{restart} invocation
  636. (or that is prompted for interactively by the debugger)
  637. in \param{place} and starts over,
  638. checking the type of the new value
  639. and signaling another error if it is still not of the desired \term{type}.
  640. % This used to say:
  641. % The \term{subforms} of \param{place} are evaluated once in the
  642. % order specified as follows: ...
  643. % Barmar said this is wrong. The first time the PLACE is evaluated, it is
  644. % evaluated using normal evaluation. It is only evaluated as a SETF place if
  645. % the type check fails and \therestart{store-value} is used.
  646. % Barrett concurs. Rewritten...
  647. The first time \param{place} is \term{evaluated},
  648. it is \term{evaluated} by normal evaluation rules.
  649. It is later \term{evaluated} as a \term{place}
  650. if the type check fails and \therestart{store-value} is used;
  651. \seesection\GenRefSubFormEval.
  652. %% I think this is now unnecessary due to the previous paragraph. -kmp 21-Nov-91
  653. % The \param{place} and its \term{subforms} might be evaluated again if
  654. % the type check fails.
  655. \term{string} should be an English description of the type,
  656. starting with an indefinite article (``a'' or ``an'').
  657. If \term{string} is not supplied,
  658. it is computed automatically from \param{typespec}.
  659. The automatically generated message mentions
  660. \param{place},
  661. its contents,
  662. and the desired type.
  663. An implementation may choose to generate
  664. a somewhat differently worded error message
  665. if it recognizes that \param{place} is of a particular form,
  666. such as one of the arguments to the function that called \macref{check-type}.
  667. \term{string} is allowed because some applications of \macref{check-type}
  668. may require a more specific description of what is wanted
  669. than can be generated automatically from \param{typespec}.
  670. \label Examples::
  671. \code
  672. (setq aardvarks '(sam harry fred))
  673. \EV (SAM HARRY FRED)
  674. (check-type aardvarks (array * (3)))
  675. \OUT Error: The value of AARDVARKS, (SAM HARRY FRED),
  676. \OUT is not a 3-long array.
  677. \OUT To continue, type :CONTINUE followed by an option number:
  678. \OUT 1: Specify a value to use instead.
  679. \OUT 2: Return to Lisp Toplevel.
  680. \OUT Debug> \IN{:CONTINUE 1}
  681. \OUT Use Value: \IN{#(SAM FRED HARRY)}
  682. \EV NIL
  683. aardvarks
  684. \EV #<ARRAY-T-3 13571>
  685. (map 'list #'identity aardvarks)
  686. \EV (SAM FRED HARRY)
  687. (setq aardvark-count 'foo)
  688. \EV FOO
  689. (check-type aardvark-count (integer 0 *) "A positive integer")
  690. \OUT Error: The value of AARDVARK-COUNT, FOO, is not a positive integer.
  691. \OUT To continue, type :CONTINUE followed by an option number:
  692. \OUT 1: Specify a value to use instead.
  693. \OUT 2: Top level.
  694. \OUT Debug> \IN{:CONTINUE 2}
  695. \endcode
  696. \code
  697. (defmacro define-adder (name amount)
  698. (check-type name (and symbol (not null)) "a name for an adder function")
  699. (check-type amount integer)
  700. `(defun ,name (x) (+ x ,amount)))
  701. (macroexpand '(define-adder add3 3))
  702. \EV (defun add3 (x) (+ x 3))
  703. (macroexpand '(define-adder 7 7))
  704. \OUT Error: The value of NAME, 7, is not a name for an adder function.
  705. \OUT To continue, type :CONTINUE followed by an option number:
  706. \OUT 1: Specify a value to use instead.
  707. \OUT 2: Top level.
  708. \OUT Debug> \IN{:Continue 1}
  709. \OUT Specify a value to use instead.
  710. \OUT Type a form to be evaluated and used instead: \IN{'ADD7}
  711. \EV (defun add7 (x) (+ x 7))
  712. (macroexpand '(define-adder add5 something))
  713. \OUT Error: The value of AMOUNT, SOMETHING, is not an integer.
  714. \OUT To continue, type :CONTINUE followed by an option number:
  715. \OUT 1: Specify a value to use instead.
  716. \OUT 2: Top level.
  717. \OUT Debug> \IN{:Continue 1}
  718. \OUT Type a form to be evaluated and used instead: \IN{5}
  719. \EV (defun add5 (x) (+ x 5))
  720. \endcode
  721. Control is transferred to a handler.
  722. \label Side Effects::
  723. The debugger might be entered.
  724. \label Affected By::
  725. \varref{*break-on-signals*}
  726. %\varref{*debug-io*}
  727. The implementation.
  728. \label Exceptional Situations:\None.
  729. %% Barrett: Not exceptional.
  730. % An error \oftype{type-error} is signaled
  731. % if the contents of \param{place} are not
  732. % of the \term{type} specified by \param{typespec}.
  733. \label See Also::
  734. {\secref\ConditionSystemConcepts}
  735. \label Notes::
  736. \code
  737. (check-type \param{place} \param{typespec})
  738. \EQ (assert (typep \param{place} '\param{typespec}) (\param{place})
  739. 'type-error :datum \param{place} :expected-type '\param{typespec})
  740. \endcode
  741. \endcom
  742. \begincom{simple-error}\ftype{Condition Type}
  743. \label Class Precedence List::
  744. \issue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  745. \typeref{simple-error},
  746. \typeref{simple-condition},
  747. \typeref{error},
  748. \typeref{serious-condition},
  749. \typeref{condition},
  750. \typeref{t}
  751. \endissue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  752. \label Description::
  753. \Thetype{simple-error} consists of \term{conditions} that
  754. are signaled by \funref{error} or \funref{cerror} when a
  755. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}%
  756. \term{format control}
  757. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}%
  758. is supplied as the function's first argument.
  759. %The default condition type for \funref{error} and
  760. %\funref{cerror} is \typeref{simple-error}.
  761. \endcom%{simple-error}\ftype{Condition Type}
  762. %%% ========== INVALID-METHOD-ERROR
  763. \begincom{invalid-method-error}\ftype{Function}
  764. \label Syntax::
  765. \DefunWithValues invalid-method-error
  766. {method format-control {\rest} args}
  767. {\term{implementation-dependent}}
  768. \label Arguments and Values::
  769. \param{method}---a \term{method}.
  770. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  771. \param{format-control}---a \term{format control}.
  772. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  773. \param{args}---\term{format arguments} for the \param{format-control}.
  774. \label Description::
  775. \Thefunction{invalid-method-error} is used to signal an error \oftype{error}
  776. when there is an applicable \term{method} whose \term{qualifiers} are not valid for
  777. the method combination type. The error message is constructed by
  778. using the \param{format-control} suitable for \funref{format}
  779. and any \param{args} to it. Because an
  780. implementation may need to add additional contextual information to
  781. the error message, \funref{invalid-method-error} should be called only
  782. within the dynamic extent of a method combination function.
  783. \Thefunction{invalid-method-error} is called automatically when a
  784. \term{method} fails to satisfy every \term{qualifier} pattern and predicate in a
  785. \macref{define-method-combination} \term{form}. A method combination function
  786. that imposes additional restrictions should call
  787. \funref{invalid-method-error} explicitly if it encounters a \term{method}
  788. it cannot accept.
  789. %!!! What does this mean? -kmp 13-Feb-91
  790. Whether \funref{invalid-method-error} returns to its caller or exits via
  791. \specref{throw} is \term{implementation-dependent}.
  792. \label Examples:\None.
  793. \label Side Effects::
  794. The debugger might be entered.
  795. \label Affected By::
  796. \varref{*break-on-signals*}
  797. \label Exceptional Situations:\None.
  798. \label See Also::
  799. \macref{define-method-combination}
  800. %% Per X3J13. -kmp 05-Oct-93
  801. \label Notes:\None.
  802. \endcom
  803. %%% ========== METHOD-COMBINATION-ERROR
  804. \begincom{method-combination-error}\ftype{Function}
  805. \label Syntax::
  806. \DefunWithValues {method-combination-error}
  807. {format-control {\rest} args}
  808. {\term{implementation-dependent}}
  809. \label Arguments and Values::
  810. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  811. \param{format-control}---a \term{format control}.
  812. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  813. \param{args}---\term{format arguments} for \param{format-control}.
  814. \label Description::
  815. \Thefunction{method-combination-error} is used to signal an error
  816. in method combination.
  817. The error message is constructed by using a \param{format-control} suitable
  818. for \funref{format} and any \param{args} to it. Because an implementation may
  819. need to add additional contextual information to the error message,
  820. \funref{method-combination-error} should be called only within the
  821. dynamic extent of a method combination function.
  822. %!!! What does this mean? -kmp 13-Feb-91
  823. Whether \funref{method-combination-error} returns to its caller or exits
  824. via \specref{throw} is \term{implementation-dependent}.
  825. %% Per X3J13. -kmp 05-Oct-93
  826. \label Examples:\None.
  827. \label Side Effects::
  828. The debugger might be entered.
  829. \label Affected By::
  830. \varref{*break-on-signals*}
  831. \label Exceptional Situations:\None.
  832. \label See Also::
  833. \macref{define-method-combination}
  834. %% Per X3J13. -kmp 05-Oct-93
  835. \label Notes:\None.
  836. \endcom
  837. %%% ========== SIGNAL
  838. \begincom{signal}\ftype{Function}
  839. \label Syntax::
  840. \DefunWithValues signal {datum {\rest} arguments} {\nil}
  841. \label Arguments and Values::
  842. \param{datum}, \param{arguments}---\term{designators} for a \term{condition}
  843. of default type \typeref{simple-condition}.
  844. \label Description::
  845. \term{Signals} the \term{condition} denoted by the given \param{datum} and \param{arguments}.
  846. If the \term{condition} is not handled, \funref{signal} returns \nil.
  847. \label Examples::
  848. \code
  849. (defun handle-division-conditions (condition)
  850. (format t "Considering condition for division condition handling~%")
  851. (when (and (typep condition 'arithmetic-error)
  852. (eq '/ (arithmetic-error-operation condition)))
  853. (invoke-debugger condition)))
  854. HANDLE-DIVISION-CONDITIONS
  855. (defun handle-other-arithmetic-errors (condition)
  856. (format t "Considering condition for arithmetic condition handling~%")
  857. (when (typep condition 'arithmetic-error)
  858. (abort)))
  859. HANDLE-OTHER-ARITHMETIC-ERRORS
  860. (define-condition a-condition-with-no-handler (condition) ())
  861. A-CONDITION-WITH-NO-HANDLER
  862. (signal 'a-condition-with-no-handler)
  863. NIL
  864. (handler-bind ((condition #'handle-division-conditions)
  865. (condition #'handle-other-arithmetic-errors))
  866. (signal 'a-condition-with-no-handler))
  867. Considering condition for division condition handling
  868. Considering condition for arithmetic condition handling
  869. NIL
  870. (handler-bind ((arithmetic-error #'handle-division-conditions)
  871. (arithmetic-error #'handle-other-arithmetic-errors))
  872. (signal 'arithmetic-error :operation '* :operands '(1.2 b)))
  873. Considering condition for division condition handling
  874. Considering condition for arithmetic condition handling
  875. Back to Lisp Toplevel
  876. \endcode
  877. \label Side Effects::
  878. The debugger might be entered due to \varref{*break-on-signals*}.
  879. Handlers for the condition being signaled might transfer control.
  880. \label Affected By::
  881. Existing handler bindings.
  882. \varref{*break-on-signals*}
  883. %\varref{*debug-io*}
  884. \label Exceptional Situations:\None.
  885. \label See Also::
  886. \varref{*break-on-signals*},
  887. \funref{error},
  888. \typeref{simple-condition},
  889. {\secref\CondSignalHandle}
  890. \label Notes::
  891. If \f{(typep \param{datum} *break-on-signals*)} \term{yields} \term{true},
  892. the debugger is entered prior to beginning the signaling process.
  893. \Therestart{continue} can be used to continue with the signaling process.
  894. This is also true for all other \term{functions} and \term{macros} that
  895. should, might, or must \term{signal} \term{conditions}.
  896. \endcom
  897. %----------------------------------------
  898. \begincom{simple-condition}\ftype{Condition Type}
  899. \label Class Precedence List::
  900. \typeref{simple-condition},
  901. \typeref{condition},
  902. \typeref{t}
  903. \label Description::
  904. \Thetype{simple-condition} represents \term{conditions} that are
  905. signaled by \funref{signal} whenever a \param{format-control} is
  906. supplied as the function's first argument.
  907. %The default \term{condition} \term{type} for \funref{signal}
  908. %and \funref{warn} is \typeref{simple-condition}.
  909. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  910. The \term{format control} and \term{format arguments} are initialized with
  911. \theinitkeyargs{format-control}
  912. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  913. and \kwd{format-arguments} to \funref{make-condition}, and are
  914. \term{accessed} by the \term{functions}
  915. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  916. \funref{simple-condition-format-control}
  917. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  918. and \funref{simple-condition-format-arguments}.
  919. If format arguments are not supplied to \funref{make-condition},
  920. \nil\ is used as a default.
  921. \label See Also::
  922. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  923. \funref{simple-condition-format-control},
  924. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  925. \funref{simple-condition-format-arguments}
  926. \endcom%{simple-condition}\ftype{Condition Type}
  927. %%% ========== SIMPLE-CONDITION-FORMAT-ARGUMENTS
  928. \begincom{simple-condition-format-control, simple-condition-format-arguments}\ftype{Function}
  929. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  930. \label Syntax::
  931. \DefunWithValues simple-condition-format-control {condition} {format-control}
  932. \DefunWithValues simple-condition-format-arguments {condition} {format-arguments}
  933. \label Arguments and Values::
  934. \param{condition}---a \term{condition} of \term{type} \typeref{simple-condition}.
  935. %% Barmar: These are all subtypes of simple-condition...
  936. % or \typeref{simple-warning}
  937. % or \typeref{simple-error}
  938. % or \typeref{simple-type-error}.
  939. \param{format-control}---a \term{format control}.
  940. \param{format-arguments}---a \term{list}.
  941. \label Description::
  942. \funref{simple-condition-format-control} returns the \term{format control} needed to
  943. process the \param{condition}'s \term{format arguments}.
  944. \funref{simple-condition-format-arguments} returns a \term{list} of \term{format arguments}
  945. needed to process the \param{condition}'s \term{format control}.
  946. \label Examples::
  947. \code
  948. (setq foo (make-condition 'simple-condition
  949. :format-control "Hi ~S"
  950. :format-arguments '(ho)))
  951. \EV #<SIMPLE-CONDITION 26223553>
  952. (apply #'format nil (simple-condition-format-control foo)
  953. (simple-condition-format-arguments foo))
  954. \EV "Hi HO"
  955. \endcode
  956. \label Side Effects:\None.
  957. \label Affected By:\None.
  958. \label Exceptional Situations:\None.
  959. \label See Also::
  960. \funref{simple-condition},
  961. {\secref\ConditionSystemConcepts}
  962. %% Per X3J13. -kmp 05-Oct-93
  963. \label Notes:\None.
  964. %% Shouldn't be needed. -kmp 1-Sep-91
  965. %It is an error to use \macref{setf} with \funref{simple-condition-format-arguments}.
  966. %It is an error to use \macref{setf} with \funref{simple-condition-format-control}.
  967. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  968. \endcom
  969. %%% ========== WARN
  970. \begincom{warn}\ftype{Function}
  971. \label Syntax::
  972. \DefunWithValues warn {datum {\rest} arguments} {\nil}
  973. \label Arguments and Values::
  974. \param{datum}, \param{arguments}---\term{designators} for a \term{condition}
  975. of default type \typeref{simple-warning}.
  976. \label Description::
  977. \term{Signals} a \term{condition} \oftype{warning}.
  978. If the \term{condition} is not \term{handled},
  979. reports the \term{condition} to \term{error output}.
  980. The precise mechanism for warning is as follows:
  981. \issue{BREAK-ON-WARNINGS-OBSOLETE:REMOVE}
  982. %Discussion of *BREAK-ON-WARNINGS* removed.
  983. \endissue{BREAK-ON-WARNINGS-OBSOLETE:REMOVE}
  984. %!!! Barret wonders whether stylistically it wouldn't be better to have just
  985. % normal text instead of this indented stuff.
  986. \beginlist
  987. \itemitem{{\bf The warning condition is signaled}}
  988. While the \typeref{warning} \term{condition} is being signaled,
  989. \therestart{muffle-warning} is established for use by a \term{handler}.
  990. If invoked, this \term{restart} bypasses further action by \funref{warn},
  991. which in turn causes \funref{warn} to immediately return \nil.
  992. \itemitem{{\bf If no handler for the warning condition is found}}
  993. If no handlers for the warning condition are found,
  994. or if all such handlers decline,
  995. then the \term{condition} is reported to \term{error output}
  996. by \funref{warn} in an \term{implementation-dependent} format.
  997. %% Barrett points out that the details of this are already said elsewhere in
  998. %% the concept info for conditions.
  999. % (with possible implementation-specific extra
  1000. % output such as motion to a fresh line before and/or after the display
  1001. % of the warning, or supplying some introductory text that might mention
  1002. % the name of the function which called \funref{warn}
  1003. % and/or the fact that this is a warning).
  1004. \itemitem{{\bf \nil\ is returned}}
  1005. The value returned by \funref{warn} if it returns is \nil.
  1006. \endlist
  1007. \label Examples::
  1008. \code
  1009. (defun foo (x)
  1010. (let ((result (* x 2)))
  1011. (if (not (typep result 'fixnum))
  1012. (warn "You're using very big numbers."))
  1013. result))
  1014. \EV FOO
  1015. (foo 3)
  1016. \EV 6
  1017. (foo most-positive-fixnum)
  1018. \OUT Warning: You're using very big numbers.
  1019. \EV 4294967294
  1020. (setq *break-on-signals* t)
  1021. \EV T
  1022. (foo most-positive-fixnum)
  1023. \OUT Break: Caveat emptor.
  1024. \OUT To continue, type :CONTINUE followed by an option number.
  1025. \OUT 1: Return from Break.
  1026. \OUT 2: Abort to Lisp Toplevel.
  1027. \OUT Debug> :continue 1
  1028. \OUT Warning: You're using very big numbers.
  1029. \EV 4294967294
  1030. \endcode
  1031. \label Side Effects::
  1032. A warning is issued. The debugger might be entered.
  1033. \label Affected By::
  1034. Existing handler bindings.
  1035. \varref{*break-on-signals*},
  1036. \varref{*error-output*}.
  1037. \label Exceptional Situations::
  1038. If \param{datum} is a \term{condition}
  1039. and if the \term{condition} is not \oftype{warning},
  1040. or \param{arguments} is \term{non-nil}, an error \oftype{type-error} is signaled.
  1041. If \param{datum} is a condition type,
  1042. the result of {\tt (apply #'make-condition datum arguments)}
  1043. must be \oftype{warning} or an error \oftype{type-error} is signaled.
  1044. \label See Also::
  1045. \varref{*break-on-signals*},
  1046. \funref{muffle-warning},
  1047. \funref{signal}
  1048. \label Notes:\None.
  1049. \endcom
  1050. \begincom{simple-warning}\ftype{Condition Type}
  1051. \label Class Precedence List::
  1052. \issue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  1053. \typeref{simple-warning},
  1054. \typeref{simple-condition},
  1055. \typeref{warning},
  1056. \typeref{condition},
  1057. \typeref{t}
  1058. \endissue{TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND}
  1059. \label Description::
  1060. \Thetype{simple-warning} represents \term{conditions} that
  1061. are signaled by \funref{warn} whenever a
  1062. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1063. \term{format control}
  1064. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1065. is supplied as the function's first argument.
  1066. \endcom%{simple-warning}\ftype{Condition Type}
  1067. %-------------------- Debugger --------------------
  1068. %%% ========== INVOKE-DEBUGGER
  1069. \begincom{invoke-debugger}\ftype{Function}
  1070. \label Syntax::
  1071. \DefunNoReturn invoke-debugger {condition}
  1072. \label Arguments and Values::
  1073. \param{condition}---a \term{condition} \term{object}.
  1074. \label Description::
  1075. \funref{invoke-debugger} attempts to enter the debugger with \param{condition}.
  1076. If \varref{*debugger-hook*} is not \nil, it should be a \term{function}
  1077. (or the name of a \term{function}) to be called prior to entry to
  1078. the standard debugger. The \term{function} is called with
  1079. \varref{*debugger-hook*} bound to \nil, and the \term{function}
  1080. must accept two arguments: the \param{condition}
  1081. and \thevalueof{*debugger-hook*} prior to binding it to \nil.
  1082. If the \term{function} returns normally,
  1083. the standard debugger is entered.
  1084. %!!! KMP: Maybe make glossary term of "standard debugger"?
  1085. The standard debugger never directly returns. Return can occur only by a
  1086. non-local transfer of control, such as the use of a restart function.
  1087. \label Examples::
  1088. \code
  1089. (ignore-errors ;Normally, this would suppress debugger entry
  1090. (handler-bind ((error #'invoke-debugger)) ;But this forces debugger entry
  1091. (error "Foo.")))
  1092. Debug: Foo.
  1093. To continue, type :CONTINUE followed by an option number:
  1094. 1: Return to Lisp Toplevel.
  1095. Debug>
  1096. \endcode
  1097. \label Side Effects::
  1098. \varref{*debugger-hook*} is bound to \nil,
  1099. program execution is discontinued,
  1100. and the debugger is entered.
  1101. \label Affected By::
  1102. \varref{*debug-io*} and \varref{*debugger-hook*}.
  1103. \label Exceptional Situations:\None.
  1104. \label See Also::
  1105. \funref{error}, \funref{break}
  1106. \label Notes:\None.
  1107. \endcom
  1108. %%% ========== BREAK
  1109. \begincom{break}\ftype{Function}
  1110. \label Syntax::
  1111. \DefunWithValues break {{\opt} format-control {\rest} format-arguments} {\nil}
  1112. \label Arguments and Values::
  1113. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1114. \param{format-control}---a \term{format control}.
  1115. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1116. \Default{\term{implementation-dependent}}
  1117. \param{format-arguments}---\term{format arguments} for the \param{format-control}.
  1118. \label Description::
  1119. %% 24.0.0 29
  1120. \funref{break} \term{formats} \param{format-control} and \param{format-arguments}
  1121. and then goes directly into the debugger without allowing any possibility of
  1122. interception by programmed error-handling facilities.
  1123. If \therestart{continue} is used while in the debugger,
  1124. \funref{break} immediately returns \nil\ without taking any unusual recovery action.
  1125. \issue{DEBUGGER-HOOK-VS-BREAK:CLARIFY}
  1126. \funref{break} binds \varref{*debugger-hook*} to \nil\
  1127. before attempting to enter the debugger.
  1128. \endissue{DEBUGGER-HOOK-VS-BREAK:CLARIFY}
  1129. \label Examples::
  1130. \code
  1131. (break "You got here with arguments: ~:S." '(FOO 37 A))
  1132. \OUT BREAK: You got here with these arguments: FOO, 37, A.
  1133. \OUT To continue, type :CONTINUE followed by an option number:
  1134. \OUT 1: Return from BREAK.
  1135. \OUT 2: Top level.
  1136. \OUT Debug> :CONTINUE 1
  1137. \OUT Return from BREAK.
  1138. \EV NIL
  1139. \endcode
  1140. \label Side Effects::
  1141. The debugger is entered.
  1142. \label Affected By::
  1143. \varref{*debug-io*}.
  1144. \label Exceptional Situations:\None.
  1145. \label See Also::
  1146. \funref{error}, \funref{invoke-debugger}.
  1147. \label Notes::
  1148. %% 24.0.0 30
  1149. \funref{break} is used as a way of inserting temporary debugging
  1150. ``breakpoints'' in a program, not as a way of signaling errors.
  1151. For this reason, \funref{break} does not take the \param{continue-format-control}
  1152. \term{argument} that \funref{cerror} takes.
  1153. This and the lack of any possibility of interception by
  1154. \term{condition} \term{handling} are the only program-visible
  1155. differences between \funref{break} and \funref{cerror}.
  1156. The user interface aspects of \funref{break} and \funref{cerror} are
  1157. permitted to vary more widely, in order to accomodate the interface
  1158. needs of the \term{implementation}. For example, it is permissible for a
  1159. \term{Lisp read-eval-print loop} to be entered by \funref{break} rather
  1160. than the conventional debugger.
  1161. \funref{break} could be defined by:
  1162. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1163. \code
  1164. (defun break (&optional (format-control "Break") &rest format-arguments)
  1165. (with-simple-restart (continue "Return from BREAK.")
  1166. (let ((*debugger-hook* nil))
  1167. (invoke-debugger
  1168. (make-condition 'simple-condition
  1169. :format-control format-control
  1170. :format-arguments format-arguments))))
  1171. nil)
  1172. \endcode
  1173. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1174. \endcom
  1175. %%% ========== *DEBUGGER-HOOK*
  1176. \begincom{*debugger-hook*}\ftype{Variable}
  1177. \label Value Type::
  1178. %!!! Barrett: What if this is invoked directly instead of from invoke-debugger?
  1179. a \term{designator} for a \term{function} of two \term{arguments}
  1180. (a \term{condition} and \thevalueof{*debugger-hook*} at the time
  1181. the debugger was entered),
  1182. or \nil.
  1183. \label Initial Value::
  1184. \nil.
  1185. \label Description::
  1186. When \thevalueof{*debugger-hook*} is \term{non-nil}, it is called prior to
  1187. normal entry into the debugger, either due to a call to \funref{invoke-debugger}
  1188. or due to automatic entry into the debugger from a call to \funref{error}
  1189. or \funref{cerror} with a condition that is not handled.
  1190. The \term{function} may either handle the \term{condition}
  1191. (transfer control) or return normally (allowing the standard debugger to run).
  1192. To minimize recursive errors while debugging,
  1193. \varref{*debugger-hook*} is bound to \nil\ by \funref{invoke-debugger}
  1194. prior to calling the \term{function}.
  1195. \label Examples::
  1196. \code
  1197. (defun one-of (choices &optional (prompt "Choice"))
  1198. (let ((n (length choices)) (i))
  1199. (do ((c choices (cdr c)) (i 1 (+ i 1)))
  1200. ((null c))
  1201. (format t "~&[~D] ~A~%" i (car c)))
  1202. (do () ((typep i `(integer 1 ,n)))
  1203. (format t "~&~A: " prompt)
  1204. (setq i (read))
  1205. (fresh-line))
  1206. (nth (- i 1) choices)))
  1207. (defun my-debugger (condition me-or-my-encapsulation)
  1208. (format t "~&Fooey: ~A" condition)
  1209. (let ((restart (one-of (compute-restarts))))
  1210. (if (not restart) (error "My debugger got an error."))
  1211. (let ((*debugger-hook* me-or-my-encapsulation))
  1212. (invoke-restart-interactively restart))))
  1213. (let ((*debugger-hook* #'my-debugger))
  1214. (+ 3 'a))
  1215. \OUT Fooey: The argument to +, A, is not a number.
  1216. \OUT [1] Supply a replacement for A.
  1217. \OUT [2] Return to Cloe Toplevel.
  1218. \OUT Choice: 1
  1219. \OUT Form to evaluate and use: (+ 5 'b)
  1220. \OUT Fooey: The argument to +, B, is not a number.
  1221. \OUT [1] Supply a replacement for B.
  1222. \OUT [2] Supply a replacement for A.
  1223. \OUT [3] Return to Cloe Toplevel.
  1224. \OUT Choice: 1
  1225. \OUT Form to evaluate and use: 1
  1226. \EV 9
  1227. \endcode
  1228. \label Affected By::
  1229. \funref{invoke-debugger}
  1230. \label See Also:\None.
  1231. \label Notes::
  1232. When evaluating code typed in by the user interactively, it is sometimes
  1233. useful to have the hook function bind \varref{*debugger-hook*} to the
  1234. \term{function} that was its second argument so that recursive errors
  1235. can be handled using the same interactive facility.
  1236. \endcom
  1237. %%% ========== *BREAK-ON-SIGNALS*
  1238. \begincom{*break-on-signals*}\ftype{Variable}
  1239. \label Value Type::
  1240. a \term{type specifier}.
  1241. \label Initial Value::
  1242. \nil.
  1243. \label Description::
  1244. %!!! Does this get involved in *debugger-hook*? What kind of break is entered?
  1245. When \f{(typep \i{condition} *break-on-signals*)} returns \term{true},
  1246. calls to \funref{signal}, and to other \term{operators} such as \funref{error}
  1247. that implicitly call \funref{signal}, enter the debugger prior to
  1248. \term{signaling} the \term{condition}.
  1249. \Therestart{continue} can be used to continue with the normal
  1250. \term{signaling} process when a break occurs process due to
  1251. \varref{*break-on-signals*}.
  1252. \label Examples::
  1253. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1254. \code
  1255. *break-on-signals* \EV NIL
  1256. (ignore-errors (error 'simple-error :format-control "Fooey!"))
  1257. \EV NIL, #<SIMPLE-ERROR 32207172>
  1258. (let ((*break-on-signals* 'error))
  1259. (ignore-errors (error 'simple-error :format-control "Fooey!")))
  1260. \OUT Break: Fooey!
  1261. \OUT BREAK entered because of *BREAK-ON-SIGNALS*.
  1262. \OUT To continue, type :CONTINUE followed by an option number:
  1263. \OUT 1: Continue to signal.
  1264. \OUT 2: Top level.
  1265. \OUT Debug> \IN{:CONTINUE 1}
  1266. \OUT Continue to signal.
  1267. \EV NIL, #<SIMPLE-ERROR 32212257>
  1268. (let ((*break-on-signals* 'error))
  1269. (error 'simple-error :format-control "Fooey!"))
  1270. \OUT Break: Fooey!
  1271. \OUT BREAK entered because of *BREAK-ON-SIGNALS*.
  1272. \OUT To continue, type :CONTINUE followed by an option number:
  1273. \OUT 1: Continue to signal.
  1274. \OUT 2: Top level.
  1275. \OUT Debug> \IN{:CONTINUE 1}
  1276. \OUT Continue to signal.
  1277. \OUT Error: Fooey!
  1278. \OUT To continue, type :CONTINUE followed by an option number:
  1279. \OUT 1: Top level.
  1280. \OUT Debug> \IN{:CONTINUE 1}
  1281. \OUT Top level.
  1282. \endcode
  1283. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1284. \label Affected By:\None.
  1285. \label See Also::
  1286. \funref{break},
  1287. \funref{signal}, \funref{warn}, \funref{error},
  1288. \funref{typep},
  1289. {\secref\ConditionSystemConcepts}
  1290. \label Notes::
  1291. \varref{*break-on-signals*} is intended primarily for use in debugging code that
  1292. does signaling. When setting \varref{*break-on-signals*}, the user is
  1293. encouraged to choose the most restrictive specification that suffices.
  1294. Setting \varref{*break-on-signals*} effectively violates the modular handling of
  1295. \term{condition} signaling. In practice, the complete effect of setting
  1296. \varref{*break-on-signals*} might be unpredictable in some cases since the user
  1297. might not be aware of the variety or number of calls to \funref{signal}
  1298. that are used in code called only incidentally.
  1299. \issue{BREAK-ON-WARNINGS-OBSOLETE:REMOVE}
  1300. % Reference to *BREAK-ON-WARNINGS* removed.
  1301. \endissue{BREAK-ON-WARNINGS-OBSOLETE:REMOVE}
  1302. \varref{*break-on-signals*} enables an early entry to the debugger but such an
  1303. entry does not preclude an additional entry to the debugger in the case of
  1304. operations such as \funref{error} and \funref{cerror}.
  1305. \endcom
  1306. %-------------------- Handling --------------------
  1307. %%% ========== HANDLER-BIND
  1308. \begincom{handler-bind}\ftype{Macro}
  1309. \label Syntax::
  1310. \DefmacWithValues handler-bind
  1311. {\paren{\stardown{binding}}
  1312. \starparam{form}}
  1313. {\starparam{result}}
  1314. \auxbnf{binding}{\paren{type handler}}
  1315. \label Arguments and Values::
  1316. \param{type}---a \term{type specifier}.
  1317. \param{handler}---a \term{form}; evaluated to produce a \param{handler-function}.
  1318. \param{handler-function}---a \term{designator} for a \term{function} of one \term{argument}.
  1319. \param{forms}---an \term{implicit progn}.
  1320. \param{results}---the \term{values} returned by the \term{forms}.
  1321. \label Description::
  1322. Executes \param{forms} in a \term{dynamic environment} where the indicated
  1323. \param{handler} \term{bindings} are in effect.
  1324. Each \param{handler} should evaluate to a \term{handler-function},
  1325. which is used to handle \term{conditions} of the given \param{type}
  1326. during execution of the \param{forms}. This \term{function} should
  1327. take a single argument, the \term{condition} being signaled.
  1328. %!!! Barmar: The next two paragraphs belong in description of signaling,
  1329. % not handling. [I agree. -kmp]
  1330. If more than one \param{handler} \term{binding} is supplied,
  1331. the \param{handler} \term{bindings} are searched sequentially from
  1332. top to bottom in search of a match (by visual analogy with \macref{typecase}).
  1333. If an appropriate \term{type} is found,
  1334. the associated handler is run in a \term{dynamic environment} where none of these
  1335. \param{handler} bindings are visible (to avoid recursive errors).
  1336. If the \term{handler} \term{declines}, the search continues for another \term{handler}.
  1337. If no appropriate \term{handler} is found, other \term{handlers} are sought
  1338. from dynamically enclosing contours. If no \term{handler} is found outside,
  1339. then \funref{signal} returns or \funref{error} enters the debugger.
  1340. \label Examples::
  1341. %Here's an example to think about as a possible replacement for the next
  1342. %couple of paragraphs...
  1343. % (defun test (x)
  1344. % (handler-bind ((unbound-variable #'(lambda (c) (use-value 'unbound c)))
  1345. % (undefined-function
  1346. % #'(lambda (c)
  1347. % (use-value #'(lambda (&rest x) (cons (cell-error-name c) x)) c))))
  1348. % (eval x)))
  1349. % (test '(frob (+ 1 2) hunoz))
  1350. In the following code, if an unbound variable error is
  1351. signaled in the body (and not handled by an intervening handler),
  1352. the first function is called.
  1353. \code
  1354. (handler-bind ((unbound-variable #'(lambda ...))
  1355. (error #'(lambda ...)))
  1356. ...)
  1357. \endcode
  1358. If any other kind of error is signaled, the second function is called.
  1359. In either case, neither handler is active while executing the code
  1360. in the associated function.
  1361. \code
  1362. (defun trap-error-handler (condition)
  1363. (format *error-output* "~&~A~&" condition)
  1364. (throw 'trap-errors nil))
  1365. (defmacro trap-errors (&rest forms)
  1366. `(catch 'trap-errors
  1367. (handler-bind ((error #'trap-error-handler))
  1368. ,@forms)))
  1369. (list (trap-errors (signal "Foo.") 1)
  1370. (trap-errors (error "Bar.") 2)
  1371. (+ 1 2))
  1372. \OUT Bar.
  1373. \EV (1 NIL 3)
  1374. \endcode
  1375. Note that ``Foo.'' is not printed because the condition made
  1376. by \funref{signal} is a \term{simple condition}, which is not \oftype{error},
  1377. so it doesn't trigger the handler for \typeref{error} set up by \f{trap-errors}.
  1378. \label Side Effects:\None.
  1379. \label Affected By:\None.
  1380. \label Exceptional Situations:\None.
  1381. \label See Also::
  1382. \macref{handler-case}
  1383. \label Notes:\None.
  1384. \endcom
  1385. %%% ========== HANDLER-CASE
  1386. \begincom{handler-case}\ftype{Macro}
  1387. \issue{DECLS-AND-DOC}
  1388. \label Syntax::
  1389. %!!! "expression" is a bad var name to use here.
  1390. \DefmacWithValues handler-case
  1391. {\param{expression}
  1392. \interleave{\stardown{error-clause} | \down{no-error-clause}}}
  1393. {\starparam{result}}
  1394. \auxbnf{clause}{\down{error-clause} | \down{no-error-clause}}
  1395. \auxbnf{error-clause}{\paren{typespec \paren{\ttbrac{var}}
  1396. \starparam{declaration} \starparam{form}}}
  1397. \auxbnf{no-error-clause}{\paren{\kwd{no-error} \param{lambda-list}
  1398. \starparam{declaration} \starparam{form}}}
  1399. %This should follow from the above BNF.
  1400. %Note: There can be no more than one \i{no-error-clause}.
  1401. \label Arguments and Values::
  1402. \param{expression}---a \term{form}.
  1403. \param{typespec}---a \term{type specifier}.
  1404. \param{var}---a \term{variable} \term{name}.
  1405. \param{lambda-list}---an \term{ordinary lambda list}.
  1406. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  1407. \param{form}---a \term{form}.
  1408. \param{results}---In the normal situation, the values returned are those that result from
  1409. the evaluation of \param{expression};
  1410. in the exceptional situation when control is transferred to a \param{clause},
  1411. the value of the last \param{form} in that \param{clause} is returned.
  1412. \label Description::
  1413. \macref{handler-case} executes \param{expression} in a \term{dynamic environment} where
  1414. various handlers are active. Each \i{error-clause} specifies how to
  1415. handle a \term{condition} matching the indicated \param{typespec}.
  1416. A \i{no-error-clause} allows the specification of a particular action
  1417. if control returns normally.
  1418. %!!! It would be nice if this reference to (TYPEP ...) and all others
  1419. % were rewritten in text fashion.
  1420. If a \term{condition} is signaled for which there is an appropriate
  1421. \i{error-clause} during the execution of \param{expression}
  1422. (\ie one for which \f{(typep \term{condition} '\param{typespec})}
  1423. returns \term{true}) and if there is no intervening handler for a
  1424. \term{condition} of that \term{type}, then control is transferred to
  1425. the body of the relevant \i{error-clause}. In this case, the
  1426. dynamic state is unwound appropriately (so that the handlers established
  1427. around the \param{expression} are no longer active), and \param{var} is bound to
  1428. the \term{condition} that had been signaled.
  1429. %!!! Barmar: HANDLER-BIND describes this better...
  1430. If more than one case is provided, those cases are made accessible
  1431. in parallel. That is, in
  1432. \code
  1433. (handler-case \i{form}
  1434. (\i{typespec1} (\i{var1}) \i{form1})
  1435. (\i{typespec2} (\i{var2}) \i{form2}))
  1436. \endcode
  1437. if the first \i{clause} (containing \i{form1}) has been selected,
  1438. the handler for the second is no longer visible (or vice versa).
  1439. The \i{clauses}
  1440. are searched sequentially from top to bottom. If there is \term{type}
  1441. overlap between \param{typespecs},
  1442. the earlier of the \i{clauses} is selected.
  1443. If \param{var}
  1444. is not needed, it can be omitted. That is, a \i{clause} such as:
  1445. \code
  1446. (\param{typespec} (\param{var}) (declare (ignore \param{var})) \param{form})
  1447. \endcode
  1448. can be written
  1449. \f{(\param{typespec} () \param{form})}.
  1450. %% Per X3J13. -kmp 05-Oct-93
  1451. %% 3 uses of HANDLER-BIND to be replaced by HANDLER-CASE in last para on page.
  1452. If there are no \param{forms} in a selected \i{clause}, the case, and therefore
  1453. \macref{handler-case}, returns \nil.
  1454. If execution of \param{expression}
  1455. returns normally and no \i{no-error-clause}
  1456. exists, the values returned by
  1457. \param{expression} are returned by \macref{handler-case}.
  1458. If execution of
  1459. \param{expression} returns normally and a \i{no-error-clause}
  1460. does exist, the values returned are used as arguments to the function
  1461. described by constructing
  1462. \f{(lambda \param{lambda-list} \starparam{form})}
  1463. from the \i{no-error-clause}, and the \term{values} of that function call are
  1464. returned by \macref{handler-case}.
  1465. %The following was added to make Barmar happy. -kmp 1-Sep-91
  1466. The handlers which were established around the \param{expression} are no longer active at the time of this call.
  1467. \label Examples::
  1468. \code
  1469. (defun assess-condition (condition)
  1470. (handler-case (signal condition)
  1471. (warning () "Lots of smoke, but no fire.")
  1472. ((or arithmetic-error control-error cell-error stream-error)
  1473. (condition)
  1474. (format nil "~S looks especially bad." condition))
  1475. (serious-condition (condition)
  1476. (format nil "~S looks serious." condition))
  1477. (condition () "Hardly worth mentioning.")))
  1478. \EV ASSESS-CONDITION
  1479. (assess-condition (make-condition 'stream-error :stream *terminal-io*))
  1480. \EV "#<STREAM-ERROR 12352256> looks especially bad."
  1481. (define-condition random-condition (condition) ()
  1482. (:report (lambda (condition stream)
  1483. (declare (ignore condition))
  1484. (princ "Yow" stream))))
  1485. \EV RANDOM-CONDITION
  1486. (assess-condition (make-condition 'random-condition))
  1487. \EV "Hardly worth mentioning."
  1488. \endcode
  1489. \label Affected By:\None.
  1490. \label Exceptional Situations:\None.
  1491. \label See Also::
  1492. \macref{handler-bind},
  1493. \macref{ignore-errors},
  1494. {\secref\ConditionSystemConcepts}
  1495. \label Notes::
  1496. \code
  1497. (handler-case form
  1498. (\i{type1} (\i{var1}) . \i{body1})
  1499. (\i{type2} (\i{var2}) . \i{body2}) ...)
  1500. \endcode
  1501. is approximately equivalent to:
  1502. \code
  1503. (block #1=#:g0001
  1504. (let ((#2=#:g0002 nil))
  1505. (tagbody
  1506. (handler-bind ((\i{type1} #'(lambda (temp)
  1507. (setq #1# temp)
  1508. (go #3=#:g0003)))
  1509. (\i{type2} #'(lambda (temp)
  1510. (setq #2# temp)
  1511. (go #4=#:g0004))) ...)
  1512. (return-from #1# form))
  1513. #3# (return-from #1# (let ((\i{var1} #2#)) . \i{body1}))
  1514. #4# (return-from #1# (let ((\i{var2} #2#)) . \i{body2})) ...)))
  1515. \endcode
  1516. \code
  1517. (handler-case form
  1518. (\i{type1} \i{(var1)} . \i{body1})
  1519. ...
  1520. (:no-error (\i{varN-1} \i{varN-2} ...) . \i{bodyN}))
  1521. \endcode
  1522. is approximately equivalent to:
  1523. \code
  1524. (block #1=#:error-return
  1525. (multiple-value-call #'(lambda (\i{varN-1} \i{varN-2} ...) . \i{bodyN})
  1526. (block #2=#:normal-return
  1527. (return-from #1#
  1528. (handler-case (return-from #2# form)
  1529. (\i{type1} (\i{var1}) . \i{body1}) ...)))))
  1530. \endcode
  1531. \endissue{DECLS-AND-DOC}
  1532. \endcom
  1533. %%% ========== IGNORE-ERRORS
  1534. \begincom{ignore-errors}\ftype{Macro}
  1535. \label Syntax::
  1536. \DefmacWithValues ignore-errors
  1537. {\starparam{form}}
  1538. {\starparam{result}}
  1539. \label Arguments and Values::
  1540. \param{forms}---an \term{implicit progn}.
  1541. \param{results}---In the normal situation,
  1542. the \term{values} of the \term{forms} are returned;
  1543. in the exceptional situation,
  1544. two values are returned: \nil\ and the \term{condition}.
  1545. \label Description::
  1546. \macref{ignore-errors} is used to prevent \term{conditions} \oftype{error}
  1547. from causing entry into the debugger.
  1548. Specifically, \macref{ignore-errors} \term{executes} \term{forms}
  1549. in a \term{dynamic environment} where a \term{handler} for
  1550. \term{conditions} \oftype{error} has been established;
  1551. if invoked, it \term{handles} such \term{conditions} by
  1552. returning two \term{values}, \nil\ and the \term{condition} that was \term{signaled},
  1553. from the \macref{ignore-errors} \term{form}.
  1554. If a \term{normal return} from the \term{forms} occurs,
  1555. any \term{values} returned are returned by \macref{ignore-errors}.
  1556. \label Examples::
  1557. \code
  1558. (defun load-init-file (program)
  1559. (let ((win nil))
  1560. (ignore-errors ;if this fails, don't enter debugger
  1561. (load (merge-pathnames (make-pathname :name program :type :lisp)
  1562. (user-homedir-pathname)))
  1563. (setq win t))
  1564. (unless win (format t "~&Init file failed to load.~%"))
  1565. win))
  1566. (load-init-file "no-such-program")
  1567. \OUT Init file failed to load.
  1568. NIL
  1569. \endcode
  1570. \label Affected By:\None.
  1571. \label Exceptional Situations:\None.
  1572. \label See Also::
  1573. \macref{handler-case}, {\secref\ConditionSystemConcepts}
  1574. \label Notes::
  1575. \code
  1576. (ignore-errors . \i{forms})
  1577. \endcode
  1578. is equivalent to:
  1579. \code
  1580. (handler-case (progn . \i{forms})
  1581. (error (condition) (values nil condition)))
  1582. \endcode
  1583. Because the second return value is a \term{condition}
  1584. in the exceptional case, it is common (but not required) to arrange
  1585. for the second return value in the normal case to be missing or \nil\ so
  1586. that the two situations can be distinguished.
  1587. \endcom
  1588. %-------------------- Condition Type Definition --------------------
  1589. %%% ========== DEFINE-CONDITION
  1590. \begincom{define-condition}\ftype{Macro}
  1591. \issue{DEFINE-CONDITION-SYNTAX:INCOMPATIBLY-MORE-LIKE-DEFCLASS+EMPHASIZE-READ-ONLY}
  1592. \editornote{KMP: This syntax stuff is still very confused and needs lots of work.}
  1593. \label Syntax::
  1594. %!!! Consider renaming "parent-type" to "supertype".
  1595. \DefmacWithValuesNewline define-condition
  1596. {name \paren{\starparam{parent-type}}
  1597. \paren{\stardown{slot-spec}}
  1598. \starparam{option}}
  1599. {name}
  1600. \auxbnf{slot-spec}{slot-name | \paren{slot-name \down{slot-option}}}
  1601. \auxbnf{slot-option}{\begininterleave
  1602. \star{\curly{\kwd{reader} \term{symbol}}} | \CR
  1603. \star{\curly{\kwd{writer} \down{function-name}}} | \CR
  1604. \star{\curly{\kwd{accessor} \term{symbol}}} | \CR
  1605. \curly{\kwd{allocation} \down{allocation-type}} | \CR
  1606. \star{\curly{\kwd{initarg} \term{symbol}}} | \CR
  1607. \curly{\kwd{initform} \term{form}} | \CR
  1608. \curly{\kwd{type} \param{type-specifier}}
  1609. \endinterleave}
  1610. \auxbnf{option}{\begininterleave
  1611. \paren{\kwd{default-initargs} \f{.} \param{initarg-list}} | \CR
  1612. \paren{\kwd{documentation} \term{string}} | \CR
  1613. \paren{\kwd{report} \i{report-name}} \endinterleave}
  1614. \auxbnf{function-name}{\curly{\term{symbol} | {\tt (setf \term{symbol})}}}
  1615. \auxbnf{allocation-type}{\kwd{instance} | \kwd{class}}
  1616. \auxbnf{report-name}{\term{string} | \term{symbol} | \term{lambda expression}}
  1617. \label Arguments and Values::
  1618. \param{name}---a \term{symbol}.
  1619. %% Reworded per Barmar #9, First Public Review.
  1620. \param{parent-type}---a \term{symbol} naming a \term{condition} \term{type}.
  1621. If no \param{parent-types} are supplied,
  1622. the \param{parent-types} default to \f{(condition)}.
  1623. \param{default-initargs}---a \term{list} of \term{keyword/value pairs}.
  1624. \editornote{KMP: This is all mixed up as to which is a slot option and which is
  1625. a main option. I'll sort that out. Also, some of this is implied
  1626. by the bnf and needn't be stated explicitly.}%!!!
  1627. \issue{CLOS-CONDITIONS:INTEGRATE}
  1628. \param{Slot-spec} -- the \term{name} of a \term{slot} or a \term{list}
  1629. consisting of the \param{slot-name} followed by zero or more \param{slot-options}.
  1630. \param{Slot-name} -- a slot name (a \term{symbol}),
  1631. the \term{list} of a slot name, or the
  1632. \term{list} of slot name/slot form pairs.
  1633. \param{Option} -- Any of the following:
  1634. \beginlist
  1635. \itemitem{\kwd{reader}}
  1636. \kwd{reader} can be supplied more than once for a given \term{slot}
  1637. and cannot be \nil.
  1638. \itemitem{\kwd{writer}}
  1639. \kwd{writer} can be supplied more than once for a given \term{slot}
  1640. and must name a \term{generic function}.
  1641. \itemitem{\kwd{accessor}}
  1642. \kwd{accessor} can be supplied more than once for a given \term{slot}
  1643. and cannot be \nil.
  1644. \itemitem{\kwd{allocation}}
  1645. \kwd{allocation} can be supplied once at most for a given \term{slot}.
  1646. The default if \kwd{allocation} is not supplied is \kwd{instance}.
  1647. \itemitem{\kwd{initarg}}
  1648. \kwd{initarg} can be supplied more than once for a given \term{slot}.
  1649. \itemitem{\kwd{initform}}
  1650. \kwd{initform} can be supplied once at most for a given \term{slot}.
  1651. \itemitem{\kwd{type}}
  1652. \kwd{type} can be supplied once at most for a given \term{slot}.
  1653. \itemitem{\kwd{documentation}}
  1654. \kwd{documentation} can be supplied once at most for a given \term{slot}.
  1655. \itemitem{\kwd{report}}
  1656. \kwd{report} can be supplied once at most.
  1657. % Removed:
  1658. % \itemitem{\kwd{conc-name}} ...
  1659. % \itemitem{\kwd{documentation}} ...
  1660. \endlist
  1661. \endissue{CLOS-CONDITIONS:INTEGRATE}
  1662. \label Description::
  1663. %!!! Barrett: Some of this stuff
  1664. \macref{define-condition} defines a new condition type called \param{name},
  1665. which is a \term{subtype} of
  1666. \issue{CLOS-CONDITIONS:INTEGRATE}
  1667. the \term{type} or \term{types} named by
  1668. \param{parent-type}.
  1669. Each \param{parent-type} argument specifies a direct \term{supertype}
  1670. of the new \term{condition}. The new \term{condition}
  1671. inherits \term{slots} and \term{methods} from each of its direct
  1672. \term{supertypes}, and so on.
  1673. \endissue{CLOS-CONDITIONS:INTEGRATE}
  1674. %% Redundant. -kmp 3-Sep-91
  1675. % \term{Objects} of this \term{condition} type have all of the
  1676. % indicated \param{slots}, plus
  1677. % any additional slots that would be available in \term{objects}
  1678. % of type \param{parent-type}.
  1679. If a slot name/slot form pair is supplied,
  1680. the slot form is a \term{form} that
  1681. can be evaluated by \funref{make-condition} to
  1682. produce a default value when an explicit value is not provided. If no
  1683. slot form
  1684. is supplied, the contents of the \param{slot}
  1685. is initialized in an
  1686. \term{implementation-dependent} way.
  1687. If the \term{type} being defined and some other
  1688. \term{type} from which it inherits
  1689. have a slot by the same name, only one slot is allocated in the
  1690. \term{condition},
  1691. but the supplied slot form overrides any slot form
  1692. that might otherwise have been inherited from a \param{parent-type}. If no
  1693. slot form is supplied, the inherited slot form (if any) is still visible.
  1694. %% This looks suspicious to me. -kmp 14-May-91
  1695. % Barrett agrees. -kmp 3-Sep-91
  1696. % Once the \term{condition} is defined,
  1697. % \funref{make-condition} accepts keywords (from \thepackage{keyword}) with the
  1698. % \term{name} of any of the designated \param{slots},
  1699. % and will initialize the corresponding \param{slots} in \term{conditions} it creates.
  1700. Accessors are created according to the same rules as used by
  1701. %\macref{defstruct}.
  1702. \macref{defclass}.
  1703. A description of \param{slot-options} follows:
  1704. \issue{CLOS-CONDITIONS:INTEGRATE}
  1705. %!!! Isn't there a way of contracting this?
  1706. \beginlist
  1707. \itemitem{\kwd{reader}}
  1708. The \kwd{reader} slot option specifies that an \term{unqualified method} is
  1709. to be defined on the \term{generic function} named by the argument
  1710. to \kwd{reader} to read the value of the given \term{slot}.
  1711. % Removed:
  1712. % \itemitem{\kwd{writer}}
  1713. % \itemitem{\kwd{accessor}}
  1714. % \itemitem{\kwd{allocation}}
  1715. \itemitem{\bull} The \kwd{initform} slot option is used to provide a default
  1716. initial value form to be used in the initialization of the \term{slot}. This
  1717. \term{form} is evaluated every time it is used to initialize the
  1718. \term{slot}. The
  1719. \term{lexical environment}
  1720. in which this \term{form} is evaluated is the lexical
  1721. \term{environment} in which the \macref{define-condition}
  1722. form was evaluated.
  1723. Note that the \term{lexical environment} refers both to variables and to
  1724. \term{functions}.
  1725. For \term{local slots}, the \term{dynamic environment} is the dynamic
  1726. \term{environment}
  1727. in which \funref{make-condition} was called; for
  1728. \term{shared slots}, the \term{dynamic environment}
  1729. is the \term{dynamic environment} in which the
  1730. \macref{define-condition} form was evaluated.
  1731. %\Seesection\ObjectCreationAndInit.
  1732. \reviewer{Barmar: Issue CLOS-CONDITIONS doesn't say this.}
  1733. No implementation is permitted to extend the syntax of \macref{define-condition}
  1734. to allow \f{(\param{slot-name} \param{form})} as an abbreviation for
  1735. \f{(\param{slot-name} :initform \param{form})}.
  1736. \itemitem{\kwd{initarg}}
  1737. The \kwd{initarg} slot option declares an initialization
  1738. argument named by its \term{symbol} argument
  1739. and specifies that this
  1740. initialization argument initializes the given \term{slot}. If the
  1741. initialization argument has a value in the call to
  1742. \funref{initialize-instance}, the value is stored into the given \term{slot},
  1743. and the slot's \kwd{initform} slot option, if any, is not
  1744. evaluated. If none of the initialization arguments specified for a
  1745. given \term{slot} has a value, the \term{slot} is initialized according to the
  1746. \kwd{initform} slot option, if specified.
  1747. \itemitem{\kwd{type}}
  1748. The \kwd{type} slot option specifies that the contents of the
  1749. \term{slot} is always of the specified \term{type}. It effectively
  1750. declares the result type of the reader generic function when applied
  1751. to an \term{object} of this \term{condition} type.
  1752. The consequences of attempting to store in a
  1753. \term{slot} a value that
  1754. does not satisfy the type of the \term{slot} is undefined.
  1755. %The \kwd{type} slot option is further discussed in \secref\SlotInheritance.
  1756. \itemitem{\kwd{default-initargs}}
  1757. \editornote{KMP: This is an option, not a slot option.}%!!!
  1758. This option is treated the same as it would be \macref{defclass}.
  1759. \itemitem{\kwd{documentation}}
  1760. \editornote{KMP: This is both an option and a slot option.}%!!!
  1761. The \kwd{documentation} slot option provides a \term{documentation string}
  1762. for the \term{slot}.
  1763. %Removed:
  1764. % \itemitem{\kwd{documentation}} ...
  1765. % \itemitem{\kwd{conc-name}} ...
  1766. \endissue{CLOS-CONDITIONS:INTEGRATE}
  1767. \itemitem{\kwd{report}}
  1768. \editornote{KMP: This is an option, not a slot option.}%!!!
  1769. \term{Condition} reporting is mediated through the \funref{print-object}
  1770. method for the \term{condition} type in question, with \varref{*print-escape*}
  1771. always being \nil. Specifying \f{(:report \param{report-name})}
  1772. in the definition of a condition type \f{C} is equivalent to:
  1773. \code
  1774. (defmethod print-object ((x c) stream)
  1775. (if *print-escape* (call-next-method) (\param{report-name} x stream)))
  1776. \endcode
  1777. If the value supplied by the argument to \kwd{report} (\param{report-name})
  1778. is a \term{symbol} or a \term{lambda expression},
  1779. it must be acceptable to
  1780. \specref{function}. \f{(function \param{report-name})}
  1781. is evaluated
  1782. in the current \term{lexical environment}.
  1783. It should return a \term{function}
  1784. of two
  1785. arguments, a \term{condition} and a \term{stream},
  1786. that prints on the \term{stream} a
  1787. description of the \term{condition}.
  1788. This \term{function} is called whenever the
  1789. \term{condition} is printed while \varref{*print-escape*} is \nil.
  1790. If \param{report-name} is a \term{string}, it is a shorthand for
  1791. \code
  1792. (lambda (condition stream)
  1793. (declare (ignore condition))
  1794. (write-string \param{report-name} stream))
  1795. \endcode
  1796. This option is processed after the new \term{condition} type has been defined,
  1797. so use of the \param{slot} accessors within the \kwd{report} function is permitted.
  1798. If this option is not supplied, information about how to report this
  1799. type of \term{condition} is inherited from the \param{parent-type}.
  1800. \endlist
  1801. % !!! Barmar: This is redundant because CLOS already says this.
  1802. % KMP: I think that until the connection between conditions and standard-class is
  1803. % clearer, it doesn't hurt to say it redundantly.
  1804. The consequences are unspecifed if an attempt is made to \term{read} a
  1805. \param{slot} that has not been explicitly initialized and that has not
  1806. been given a default value.
  1807. The consequences are unspecified if an attempt is made to assign the
  1808. \param{slots} by using \macref{setf}.
  1809. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  1810. % added qualification about top-level-ness --sjl 5 Mar 92
  1811. If a \macref{define-condition} \term{form} appears as a \term{top level form},
  1812. the \term{compiler} must make \param{name} recognizable as a valid \term{type} name,
  1813. and it must be possible to reference the \term{condition} \term{type} as the
  1814. \param{parent-type} of another \term{condition} \term{type} in a subsequent
  1815. \macref{define-condition} \term{form} in the \term{file} being compiled.
  1816. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  1817. \label Examples::
  1818. The following form defines a condition of \term{type}
  1819. \f{peg/hole-mismatch} which inherits from a condition type
  1820. called \f{blocks-world-error}:
  1821. \code
  1822. (define-condition peg/hole-mismatch
  1823. (blocks-world-error)
  1824. ((peg-shape :initarg :peg-shape
  1825. :reader peg/hole-mismatch-peg-shape)
  1826. (hole-shape :initarg :hole-shape
  1827. :reader peg/hole-mismatch-hole-shape))
  1828. (:report (lambda (condition stream)
  1829. (format stream "A ~A peg cannot go in a ~A hole."
  1830. (peg/hole-mismatch-peg-shape condition)
  1831. (peg/hole-mismatch-hole-shape condition)))))
  1832. \endcode
  1833. The new type has slots \f{peg-shape} and \f{hole-shape},
  1834. so \funref{make-condition} accepts \f{:peg-shape} and \f{:hole-shape} keywords.
  1835. The \term{readers} \f{peg/hole-mismatch-peg-shape} and \f{peg/hole-mismatch-hole-shape}
  1836. apply to objects of this type, as illustrated in the \kwd{report} information.
  1837. The following form defines a \term{condition} \term{type} named \f{machine-error}
  1838. which inherits from \typeref{error}:
  1839. \code
  1840. (define-condition machine-error
  1841. (error)
  1842. ((machine-name :initarg :machine-name
  1843. :reader machine-error-machine-name))
  1844. (:report (lambda (condition stream)
  1845. (format stream "There is a problem with ~A."
  1846. (machine-error-machine-name condition)))))
  1847. \endcode
  1848. Building on this definition, a new error condition can be defined which
  1849. is a subtype of \f{machine-error} for use when machines are not available:
  1850. \code
  1851. (define-condition machine-not-available-error (machine-error) ()
  1852. (:report (lambda (condition stream)
  1853. (format stream "The machine ~A is not available."
  1854. (machine-error-machine-name condition)))))
  1855. \endcode
  1856. This defines a still more specific condition, built upon
  1857. \f{machine-not-available-error}, which provides a slot initialization form
  1858. for \f{machine-name} but which does not provide any new slots or report
  1859. information. It just gives the \f{machine-name} slot a default initialization:
  1860. \code
  1861. (define-condition my-favorite-machine-not-available-error
  1862. (machine-not-available-error)
  1863. ((machine-name :initform "mc.lcs.mit.edu")))
  1864. \endcode
  1865. Note that since no \kwd{report} clause was given, the information
  1866. inherited from \f{machine-not-available-error} is used to
  1867. report this type of condition.
  1868. \code
  1869. (define-condition ate-too-much (error)
  1870. ((person :initarg :person :reader ate-too-much-person)
  1871. (weight :initarg :weight :reader ate-too-much-weight)
  1872. (kind-of-food :initarg :kind-of-food
  1873. :reader :ate-too-much-kind-of-food)))
  1874. \EV ATE-TOO-MUCH
  1875. (define-condition ate-too-much-ice-cream (ate-too-much)
  1876. ((kind-of-food :initform 'ice-cream)
  1877. (flavor :initarg :flavor
  1878. :reader ate-too-much-ice-cream-flavor
  1879. :initform 'vanilla ))
  1880. (:report (lambda (condition stream)
  1881. (format stream "~A ate too much ~A ice-cream"
  1882. (ate-too-much-person condition)
  1883. (ate-too-much-ice-cream-flavor condition)))))
  1884. \EV ATE-TOO-MUCH-ICE-CREAM
  1885. (make-condition 'ate-too-much-ice-cream
  1886. :person 'fred
  1887. :weight 300
  1888. :flavor 'chocolate)
  1889. \EV #<ATE-TOO-MUCH-ICE-CREAM 32236101>
  1890. (format t "~A" *)
  1891. \OUT FRED ate too much CHOCOLATE ice-cream
  1892. \EV NIL
  1893. \endcode
  1894. \label Affected By:\None.
  1895. \label Exceptional Situations:\None.
  1896. \label See Also::
  1897. \funref{make-condition}, \macref{defclass}, {\secref\ConditionSystemConcepts}
  1898. %% Per X3J13. -kmp 05-Oct-93
  1899. \label Notes:\None.
  1900. \endissue{DEFINE-CONDITION-SYNTAX:INCOMPATIBLY-MORE-LIKE-DEFCLASS+EMPHASIZE-READ-ONLY}
  1901. \endcom
  1902. %-------------------- Condition Instantiation --------------------
  1903. %%% ========== MAKE-CONDITION
  1904. \begincom{make-condition}\ftype{Function}
  1905. \label Syntax::
  1906. \DefunWithValues make-condition {type {\rest} slot-initializations} {condition}
  1907. \label Arguments and Values::
  1908. %Barmar: a condition type or condition type name ?
  1909. %Barrett worried about the same thing. I think the intent was that it be a subtype of
  1910. %condition, so I've required that explicitly. -kmp 3-Sep-91
  1911. \param{type}---a \term{type specifier} (for a \term{subtype} of \typeref{condition}).
  1912. \param{slot-initializations}---an \term{initialization argument list}.
  1913. \param{condition}---a \term{condition}.
  1914. \label Description::
  1915. Constructs and returns a \term{condition} of type \param{type}
  1916. using \param{slot-initializations} for the initial values of the slots.
  1917. The newly created \term{condition} is returned.
  1918. \label Examples::
  1919. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1920. \code
  1921. (defvar *oops-count* 0)
  1922. (setq a (make-condition 'simple-error
  1923. :format-control "This is your ~:R error."
  1924. :format-arguments (list (incf *oops-count*))))
  1925. \EV #<SIMPLE-ERROR 32245104>
  1926. (format t "~&~A~%" a)
  1927. \OUT This is your first error.
  1928. \EV NIL
  1929. (error a)
  1930. \OUT Error: This is your first error.
  1931. \OUT To continue, type :CONTINUE followed by an option number:
  1932. \OUT 1: Return to Lisp Toplevel.
  1933. \OUT Debug>
  1934. \endcode
  1935. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  1936. \label Side Effects:\None.
  1937. %% Sandra thinks this is excessive.
  1938. %Creates a \term{condition}.
  1939. \label Affected By::
  1940. The set of defined \term{condition} \term{types}.
  1941. \label Exceptional Situations:\None.
  1942. \label See Also::
  1943. \macref{define-condition}, {\secref\ConditionSystemConcepts}
  1944. \label Notes:\None.
  1945. \endcom
  1946. %-------------------- Restarts --------------------
  1947. \begincom{restart}\ftype{System Class}
  1948. \label Class Precedence List::
  1949. \typeref{restart},
  1950. \typeref{t}
  1951. \label Description::
  1952. An \term{object} \oftype{restart} represents a \term{function} that can be
  1953. called to perform some form of recovery action, usually a transfer of control
  1954. to an outer point in the running program.
  1955. An \term{implementation} is free to implement a \term{restart} in whatever
  1956. manner is most convenient; a \term{restart} has only \term{dynamic extent}
  1957. relative to the scope of the binding \term{form} which \term{establishes} it.
  1958. \endcom%{restart}\ftype{System Class}
  1959. %%% ========== COMPUTE-RESTARTS
  1960. \begincom{compute-restarts}\ftype{Function}
  1961. \label Syntax::
  1962. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  1963. \DefunWithValues compute-restarts {{\opt} condition} {restarts}
  1964. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  1965. \label Arguments and Values::
  1966. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  1967. \param{condition}---a \term{condition} \term{object}, or \nil.
  1968. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  1969. \param{restarts}---a \term{list} of \term{restarts}.
  1970. \label Description::
  1971. \funref{compute-restarts} uses the dynamic state of the program to compute
  1972. a \term{list} of the \term{restarts} which are currently active.
  1973. The resulting \term{list} is ordered so that the innermost
  1974. (more-recently established) restarts are nearer the head of the \term{list}.
  1975. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  1976. When \param{condition} is \term{non-nil}, only those \term{restarts}
  1977. are considered that are either explicitly associated with that \param{condition},
  1978. or not associated with any \term{condition}; that is, the excluded \term{restarts}
  1979. are those that are associated with a non-empty set of \term{conditions} of
  1980. which the given \param{condition} is not an \term{element}.
  1981. If \param{condition} is \nil, all \term{restarts} are considered.
  1982. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  1983. \funref{compute-restarts} returns all
  1984. %"valid" -> "applicable" per Barrett
  1985. \term{applicable restarts},
  1986. including anonymous ones, even if some of them have the same name as
  1987. others and would therefore not be found by \funref{find-restart}
  1988. when given a \term{symbol} argument.
  1989. Implementations are permitted, but not required, to return \term{distinct}
  1990. \term{lists} from repeated calls to \funref{compute-restarts} while in
  1991. the same dynamic environment.
  1992. The consequences are undefined if the \term{list} returned by
  1993. \funref{compute-restarts} is every modified.
  1994. \label Examples::
  1995. \code
  1996. ;; One possible way in which an interactive debugger might present
  1997. ;; restarts to the user.
  1998. (defun invoke-a-restart ()
  1999. (let ((restarts (compute-restarts)))
  2000. (do ((i 0 (+ i 1)) (r restarts (cdr r))) ((null r))
  2001. (format t "~&~D: ~A~%" i (car r)))
  2002. (let ((n nil) (k (length restarts)))
  2003. (loop (when (and (typep n 'integer) (>= n 0) (< n k))
  2004. (return t))
  2005. (format t "~&Option: ")
  2006. (setq n (read))
  2007. (fresh-line))
  2008. (invoke-restart-interactively (nth n restarts)))))
  2009. (restart-case (invoke-a-restart)
  2010. (one () 1)
  2011. (two () 2)
  2012. (nil () :report "Who knows?" 'anonymous)
  2013. (one () 'I)
  2014. (two () 'II))
  2015. \OUT 0: ONE
  2016. \OUT 1: TWO
  2017. \OUT 2: Who knows?
  2018. \OUT 3: ONE
  2019. \OUT 4: TWO
  2020. \OUT 5: Return to Lisp Toplevel.
  2021. \OUT Option: \IN{4}
  2022. \EV II
  2023. ;; Note that in addition to user-defined restart points, COMPUTE-RESTARTS
  2024. ;; also returns information about any system-supplied restarts, such as
  2025. ;; the "Return to Lisp Toplevel" restart offered above.
  2026. \endcode
  2027. \label Side Effects:\None.
  2028. \label Affected By::
  2029. Existing restarts.
  2030. \label Exceptional Situations:\None.
  2031. \label See Also::
  2032. \funref{find-restart},
  2033. \funref{invoke-restart},
  2034. \funref{restart-bind}
  2035. \label Notes:\None.
  2036. \endcom
  2037. %%% ========== FIND-RESTART
  2038. \begincom{find-restart}\ftype{Function}
  2039. \label Syntax::
  2040. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2041. \Defun find-restart {identifier {\opt} condition} {restart}
  2042. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2043. \label Arguments and Values::
  2044. \param{identifier}---a \term{non-nil} \term{symbol}, or a \term{restart}.
  2045. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2046. \param{condition}---a \term{condition} \term{object}, or \nil.
  2047. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2048. \param{restart}---a \term{restart} or \nil.
  2049. \label Description::
  2050. \funref{find-restart} searches for a particular \term{restart} in the
  2051. current \term{dynamic environment}.
  2052. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2053. When \param{condition} is \term{non-nil}, only those \term{restarts}
  2054. are considered that are either explicitly associated with that \param{condition},
  2055. or not associated with any \term{condition}; that is, the excluded \term{restarts}
  2056. are those that are associated with a non-empty set of \term{conditions} of
  2057. which the given \param{condition} is not an \term{element}.
  2058. If \param{condition} is \nil, all \term{restarts} are considered.
  2059. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2060. If \param{identifier} is a \term{symbol}, then the innermost
  2061. (most recently established) \term{applicable restart} with that \term{name} is returned.
  2062. \nil\ is returned if no such restart is found.
  2063. If \param{identifier} is a currently active restart, then it is returned.
  2064. Otherwise, \nil\ is returned.
  2065. \label Examples::
  2066. \code
  2067. (restart-case
  2068. (let ((r (find-restart 'my-restart)))
  2069. (format t "~S is named ~S" r (restart-name r)))
  2070. (my-restart () nil))
  2071. \OUT #<RESTART 32307325> is named MY-RESTART
  2072. \EV NIL
  2073. (find-restart 'my-restart)
  2074. \EV NIL
  2075. \endcode
  2076. \label Side Effects:\None.
  2077. \label Affected By::
  2078. Existing restarts.
  2079. \macref{restart-case}, \macref{restart-bind}, \macref{with-condition-restarts}.
  2080. \label Exceptional Situations:\None.
  2081. \label See Also::
  2082. \funref{compute-restarts}
  2083. \label Notes::
  2084. \code
  2085. (find-restart \param{identifier})
  2086. \EQ (find \param{identifier} (compute-restarts) :key :restart-name)
  2087. \endcode
  2088. Although anonymous restarts have a name of \nil,
  2089. the consequences are unspecified if \nil\ is given as an \param{identifier}.
  2090. Occasionally, programmers lament that \nil\ is not permissible as an
  2091. \param{identifier} argument. In most such cases, \funref{compute-restarts}
  2092. can probably be used to simulate the desired effect.
  2093. \endcom
  2094. %%% ========== INVOKE-RESTART
  2095. \begincom{invoke-restart}\ftype{Function}
  2096. \label Syntax::
  2097. \DefunWithValues invoke-restart
  2098. {restart {\rest} arguments}
  2099. {\starparam{result}}
  2100. \label Arguments and Values::
  2101. \param{restart}---a \term{restart designator}.
  2102. \param{argument}---an \term{object}.
  2103. \param{results}---the \term{values} returned by the \term{function}
  2104. associated with \param{restart}, if that \term{function} returns.
  2105. \label Description::
  2106. Calls the \term{function} associated with \param{restart},
  2107. passing \param{arguments} to it.
  2108. \param{Restart} must be valid in the current \term{dynamic environment}.
  2109. \label Examples::
  2110. \code
  2111. (defun add3 (x) (check-type x number) (+ x 3))
  2112. (foo 'seven)
  2113. \OUT Error: The value SEVEN was not of type NUMBER.
  2114. \OUT To continue, type :CONTINUE followed by an option number:
  2115. \OUT 1: Specify a different value to use.
  2116. \OUT 2: Return to Lisp Toplevel.
  2117. \OUT Debug> \IN{(invoke-restart 'store-value 7)}
  2118. \EV 10
  2119. \endcode
  2120. \label Side Effects::
  2121. %!!! Barmar: This is true whenever calling random functions.
  2122. A non-local transfer of control might be done by the restart.
  2123. \label Affected By::
  2124. Existing restarts.
  2125. \label Exceptional Situations::
  2126. If \param{restart} is not valid, an error \oftype{control-error} is signaled.
  2127. \label See Also::
  2128. \funref{find-restart},
  2129. \macref{restart-bind},
  2130. \macref{restart-case},
  2131. \funref{invoke-restart-interactively}
  2132. \label Notes::
  2133. The most common use for \funref{invoke-restart} is in a \term{handler}.
  2134. It might be used explicitly, or implicitly through \funref{invoke-restart-interactively}
  2135. or a \term{restart function}.
  2136. \term{Restart functions} call \funref{invoke-restart}, not vice versa. That is,
  2137. \term{invoke-restart} provides primitive functionality, and \term{restart functions}
  2138. are non-essential ``syntactic sugar.''
  2139. \endcom
  2140. %%% ========== INVOKE-RESTART-INTERACTIVELY
  2141. \begincom{invoke-restart-interactively}\ftype{Function}
  2142. \label Syntax::
  2143. \DefunWithValues invoke-restart-interactively {restart} {\starparam{result}}
  2144. \label Arguments and Values::
  2145. \param{restart}---a \term{restart designator}.
  2146. \param{results}---the \term{values} returned by the \term{function}
  2147. associated with \param{restart}, if that \term{function} returns.
  2148. \label Description::
  2149. \funref{invoke-restart-interactively} calls the \term{function} associated
  2150. with \param{restart}, prompting for any necessary arguments.
  2151. If \param{restart} is a name, it must be valid in the current \term{dynamic environment}.
  2152. \funref{invoke-restart-interactively}
  2153. prompts for arguments by executing
  2154. the code provided in the \kwd{interactive} keyword to
  2155. \macref{restart-case} or
  2156. \kwd{interactive-function} keyword to \macref{restart-bind}.
  2157. %!!! Barrett: Make consistent with wrong # of args errors.
  2158. If no such options have been supplied in the corresponding
  2159. \macref{restart-bind} or \macref{restart-case},
  2160. then the consequences are undefined if the \param{restart} takes
  2161. required arguments. If the arguments are optional, an argument list of
  2162. \nil\ is used.
  2163. Once the arguments have been determined,
  2164. \funref{invoke-restart-interactively}
  2165. executes the following:
  2166. \code
  2167. (apply #'invoke-restart \i{restart} \i{arguments})
  2168. \endcode
  2169. \label Examples::
  2170. \code
  2171. (defun add3 (x) (check-type x number) (+ x 3))
  2172. (add3 'seven)
  2173. \OUT Error: The value SEVEN was not of type NUMBER.
  2174. \OUT To continue, type :CONTINUE followed by an option number:
  2175. \OUT 1: Specify a different value to use.
  2176. \OUT 2: Return to Lisp Toplevel.
  2177. \OUT Debug> \IN{(invoke-restart-interactively 'store-value)}
  2178. \OUT Type a form to evaluate and use: \IN{7}
  2179. \EV 10
  2180. \endcode
  2181. \label Side Effects::
  2182. If prompting for arguments is necesary,
  2183. some typeout may occur (on \term{query I/O}).
  2184. %!!! Barmar: This is true whenever calling random functions.
  2185. A non-local transfer of control might be done by the restart.
  2186. \label Affected By::
  2187. \varref{*query-io*}, active \term{restarts}
  2188. \label Exceptional Situations::
  2189. If \param{restart} is not valid, an error \oftype{control-error}
  2190. is signaled.
  2191. \label See Also::
  2192. \funref{find-restart},
  2193. \funref{invoke-restart},
  2194. \macref{restart-case},
  2195. \macref{restart-bind}
  2196. \label Notes::
  2197. \funref{invoke-restart-interactively} is used internally by the debugger
  2198. and may also be useful in implementing other portable, interactive debugging
  2199. tools.
  2200. \endcom
  2201. %%% ========== RESTART-BIND
  2202. \begincom{restart-bind}\ftype{Macro}
  2203. \label Syntax::
  2204. \DefmacWithValuesNewline restart-bind
  2205. {\paren{\curly{\paren{name function
  2206. \stardown{key-val-pair}}}}
  2207. \starparam{form}}
  2208. {\starparam{result}}
  2209. %!!! Barmar: Somehow indicate that each may be supplied at most once.
  2210. \auxbnf{key-val-pair}{\kwd{interactive-function} {interactive-function} | \CR
  2211. \kwd{report-function} {report-function} | \CR
  2212. \kwd{test-function} {test-function}}
  2213. \label Arguments and Values::
  2214. \param{name}---a \term{symbol}; \noeval.
  2215. \param{function}---a \term{form}; \eval.
  2216. \param{forms}---an \term{implicit progn}.
  2217. \param{interactive-function}---a \term{form}; \eval.
  2218. \param{report-function}---a \term{form}; \eval.
  2219. \param{test-function}---a \term{form}; \eval.
  2220. \param{results}---the \term{values} returned by the \term{forms}.
  2221. \label Description::
  2222. \macref{restart-bind} executes the body of \param{forms}
  2223. in a \term{dynamic environment} where \term{restarts} with the given \param{names} are in effect.
  2224. If a \param{name} is \nil, it indicates an anonymous restart;
  2225. if a \param{name} is a \term{non-nil} \term{symbol}, it indicates a named restart.
  2226. The \param{function}, \param{interactive-function}, and \param{report-function}
  2227. are unconditionally evaluated in the current lexical and dynamic environment
  2228. prior to evaluation of the body. Each of these \term{forms} must evaluate to
  2229. a \term{function}.
  2230. If \funref{invoke-restart} is done on that restart,
  2231. the \term{function} which resulted from evaluating \param{function}
  2232. is called, in the \term{dynamic environment} of the \funref{invoke-restart},
  2233. with the \term{arguments} given to \funref{invoke-restart}.
  2234. The \term{function} may either perform a non-local transfer of control or may return normally.
  2235. If the restart is invoked interactively from the debugger
  2236. (using \funref{invoke-restart-interactively}),
  2237. the arguments are defaulted by calling the \term{function}
  2238. which resulted from evaluating \param{interactive-function}.
  2239. That \term{function} may optionally prompt interactively on \term{query I/O},
  2240. and should return a \term{list} of arguments to be used by
  2241. \funref{invoke-restart-interactively} when invoking the restart.
  2242. If a restart is invoked interactively but no \param{interactive-function} is used,
  2243. then an argument list of \nil\ is used. In that case, the \term{function}
  2244. must be compatible with an empty argument list.
  2245. If the restart is presented interactively (\eg by the debugger),
  2246. the presentation is done by calling the \term{function} which resulted
  2247. from evaluating \param{report-function}.
  2248. This \term{function} must be a \term{function} of one argument, a \term{stream}.
  2249. It is expected to print a description of the action that the restart takes
  2250. to that \term{stream}.
  2251. This \term{function} is called any time the restart is printed
  2252. while \varref{*print-escape*} is \nil.
  2253. In the case of interactive invocation,
  2254. the result is dependent on the value of \kwd{interactive-function}
  2255. as follows.
  2256. \beginlist
  2257. \itemitem{\kwd{interactive-function}}
  2258. \param{Value} is evaluated in the current lexical environment and
  2259. should return a \term{function} of no arguments which constructs a
  2260. \term{list} of arguments to be used by \funref{invoke-restart-interactively}
  2261. when invoking this restart. The \term{function} may prompt interactively
  2262. using \term{query I/O} if necessary.
  2263. \itemitem{\kwd{report-function}}
  2264. \param{Value} is evaluated in the current lexical environment and
  2265. should return a \term{function} of one argument, a \term{stream}, which
  2266. prints on the \term{stream} a summary of the action that this restart
  2267. takes. This \term{function} is called whenever the restart is
  2268. reported (printed while \varref{*print-escape*} is \nil).
  2269. % This next was added for Barmar. -kmp 1-Sep-91
  2270. If no \kwd{report-function} option is provided, the manner in which the
  2271. \term{restart} is reported is \term{implementation-dependent}.
  2272. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2273. \itemitem{\kwd{test-function}}
  2274. \param{Value} is evaluated in the current lexical environment and
  2275. should return a \term{function} of one argument, a \term{condition}, which
  2276. returns \term{true} if the restart is to be considered visible.
  2277. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2278. \endlist
  2279. % \label Examples::
  2280. %
  2281. %\code
  2282. % (defun choose-an-interactive-restart ()
  2283. % (restart-bind
  2284. % ((optional-value
  2285. % #'(lambda (&optional (x 'default)) x)
  2286. % :report-function #'(lambda (stream)
  2287. % (format stream "Return an optional value")))\kern-3pt
  2288. % (return-value
  2289. % #'identity
  2290. % :report-function #'(lambda (stream)
  2291. % (format stream "Return the given value"))
  2292. % :interactive-function #'(lambda ()
  2293. % (format t "Enter a value to return: ")
  2294. % (list (eval (read))))))
  2295. % (let ((cases (compute-restarts))
  2296. % (*print-structure* t)
  2297. % (index -1))
  2298. % (dolist (case cases)
  2299. % (format t "~&~D: ~A~%" (incf index) case))
  2300. % (format t "Please enter restart to invoke: ")
  2301. % (invoke-restart-interactively (nth (eval (read)) cases)))))
  2302. %\EV\ CHOOSE-AN-INTERACTIVE-RESTART
  2303. % (choose-an-interactive-restart)
  2304. %\EV\ 0: Return an optional value
  2305. %1: Return the given value
  2306. %2: Abort to Lisp Top Level
  2307. %Please enter restart to invoke: 0
  2308. %DEFAULT
  2309. % (choose-an-interactive-restart)
  2310. %\EV\ 0: Return an optional value
  2311. %1: Return the given value
  2312. %2: Abort to Lisp Top Level
  2313. %Please enter restart to invoke: 1
  2314. %Enter a value to return: t
  2315. %T
  2316. %\endcode
  2317. \label Side Effects:\None.
  2318. \label Affected By::
  2319. \varref{*query-io*}.
  2320. \label Exceptional Situations:\None.
  2321. \label See Also::
  2322. \macref{restart-case}, \macref{with-simple-restart}
  2323. \label Notes::
  2324. \macref{restart-bind} is primarily intended to be used to implement
  2325. \macref{restart-case} and might be useful in implementing other
  2326. macros. Programmers who are uncertain about whether to use \macref{restart-case}
  2327. or \macref{restart-bind} should prefer \macref{restart-case} for the cases where
  2328. it is powerful enough, using \macref{restart-bind} only in cases where its full
  2329. generality is really needed.
  2330. \endcom
  2331. %%% ========== RESTART-CASE
  2332. \begincom{restart-case}\ftype{Macro}
  2333. \issue{DECLS-AND-DOC}
  2334. \label Syntax::
  2335. \DefmacWithValues restart-case
  2336. {restartable-form {\curly{\down{clause}}}}
  2337. {\starparam{result}}
  2338. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2339. \auxbnf{clause}{\lparen case-name lambda-list \CR
  2340. \ \interleave{\kwd{interactive} interactive-expression |
  2341. \kwd{report} report-expression |
  2342. \kwd{test} test-expression} \CR
  2343. \ \starparam{declaration} \starparam{form}\rparen}
  2344. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2345. \label Arguments and Values::
  2346. \param{restartable-form}---a \term{form}.
  2347. \param{case-name}---a \term{symbol} or \nil.
  2348. \param{lambda-list}---an \term{ordinary lambda list}.
  2349. \param{interactive-expression}---a \term{symbol} or a \term{lambda expression}.
  2350. \param{report-expression}---a \term{string},
  2351. a \term{symbol},
  2352. or a \term{lambda expression}.
  2353. \param{test-expression}---a \term{symbol} or a \term{lambda expression}.
  2354. \param{declaration}---a \misc{declare} \term{expression}; \noeval.
  2355. \param{form}---a \term{form}.
  2356. \param{results}---the \term{values} resulting from the \term{evaluation}
  2357. of \param{restartable-form},
  2358. or the \term{values} returned by the last \param{form}
  2359. executed in a chosen \term{clause},
  2360. or \nil.
  2361. \label Description::
  2362. \macref{restart-case} evaluates \param{restartable-form} in a \term{dynamic environment}
  2363. where the clauses have special meanings as points to which control may be transferred.
  2364. If \param{restartable-form} finishes executing and returns any values,
  2365. all values returned are returned by \macref{restart-case} and
  2366. processing has completed. While \param{restartable-form} is executing, any code may
  2367. transfer control to one of the clauses (see \funref{invoke-restart}).
  2368. If a transfer
  2369. occurs, the forms in the body of that clause is evaluated and any values
  2370. returned by the last such form are returned by
  2371. \macref{restart-case}.
  2372. In this case, the
  2373. dynamic state is unwound appropriately (so that the restarts established
  2374. around the \param{restartable-form} are no longer active) prior to execution of the
  2375. clause.
  2376. If there are no \param{forms}
  2377. in a selected clause, \macref{restart-case} returns \nil.
  2378. If \param{case-name} is a \term{symbol}, it names this restart.
  2379. It is possible to have more than one clause use the same \param{case-name}.
  2380. In this case, the first clause with that name is found by \funref{find-restart}.
  2381. The other clauses are accessible using \funref{compute-restarts}.
  2382. Each \param{arglist} is an \term{ordinary lambda list} to be bound during the
  2383. execution of its corresponding \param{forms}. These parameters are used
  2384. by the \macref{restart-case} clause to receive any necessary data from a call
  2385. to \funref{invoke-restart}.
  2386. By default, \funref{invoke-restart-interactively} passes no arguments and
  2387. all arguments must be optional in order to accomodate interactive
  2388. restarting. However, the arguments need not be optional if the
  2389. \kwd{interactive}
  2390. keyword has been used to inform \funref{invoke-restart-interactively}
  2391. about how to compute a proper argument list.
  2392. \param{Keyword} options have the following meaning.
  2393. \beginlist
  2394. \itemitem{\kwd{interactive}}
  2395. The \param{value} supplied by \f{:interactive \param{value}}
  2396. must be a suitable argument to \specref{function}.
  2397. \f{(function \param{value})} is evaluated in the current lexical
  2398. environment. It should return a \term{function} of no arguments which
  2399. returns arguments to be used by
  2400. \funref{invoke-restart-interactively} when it is invoked.
  2401. \funref{invoke-restart-interactively}
  2402. is called in the dynamic
  2403. environment available prior to any restart attempt, and uses
  2404. \term{query I/O} for user interaction.
  2405. If a restart is invoked interactively but no \kwd{interactive} option
  2406. was supplied, the argument list used in the invocation is the empty
  2407. list.
  2408. \itemitem{\kwd{report}}
  2409. If the \param{value} supplied by \f{:report \param{value}}
  2410. is a \term{lambda expression} or a \term{symbol}, it
  2411. must be acceptable to \specref{function}.
  2412. \f{(function \param{value})} is evaluated in the current lexical
  2413. environment. It should return a \term{function} of one
  2414. argument, a \term{stream}, which prints on the \term{stream} a
  2415. description of the restart. This \term{function} is called
  2416. whenever the restart is printed while \varref{*print-escape*} is \nil.
  2417. If \param{value} is a \term{string}, it is a shorthand for
  2418. \code
  2419. (lambda (stream) (write-string value stream))
  2420. \endcode
  2421. If a named restart is asked to report but no report information has been
  2422. supplied, the name of the restart is used in generating default report text.
  2423. When \varref{*print-escape*} is \nil, the
  2424. printer uses the report information for
  2425. a restart. For example, a debugger might announce the action of typing
  2426. a ``continue'' command by:
  2427. \code
  2428. (format t "~&~S -- ~A~%" ':continue some-restart)
  2429. \endcode
  2430. which might then display as something like:
  2431. \code
  2432. :CONTINUE -- Return to command level
  2433. \endcode
  2434. The consequences are unspecified if an unnamed restart is specified
  2435. but no \kwd{report} option is provided.
  2436. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2437. \itemitem{\kwd{test}}
  2438. The \param{value} supplied by \f{:test \param{value}}
  2439. must be a suitable argument to \specref{function}.
  2440. \f{(function \param{value})} is evaluated in the current lexical
  2441. environment. It should return a \term{function} of one \term{argument}, the
  2442. \term{condition}, that
  2443. returns \term{true} if the restart is to be considered visible.
  2444. The default for this option is equivalent to \f{(lambda (c) (declare (ignore c)) t)}.
  2445. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2446. \endlist
  2447. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2448. If the \param{restartable-form} is a \term{list} whose \term{car} is any of
  2449. the \term{symbols} \funref{signal}, \funref{error}, \funref{cerror},
  2450. or \funref{warn} (or is a \term{macro form} which macroexpands into such a
  2451. \term{list}), then \macref{with-condition-restarts} is used implicitly
  2452. to associate the indicated \term{restarts} with the \term{condition} to be
  2453. signaled.
  2454. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2455. \label Examples::
  2456. \code
  2457. (restart-case
  2458. (handler-bind ((error #'(lambda (c)
  2459. (declare (ignore condition))
  2460. (invoke-restart 'my-restart 7))))
  2461. (error "Foo."))
  2462. (my-restart (&optional v) v))
  2463. \EV 7
  2464. (define-condition food-error (error) ())
  2465. \EV FOOD-ERROR
  2466. (define-condition bad-tasting-sundae (food-error)
  2467. ((ice-cream :initarg :ice-cream :reader bad-tasting-sundae-ice-cream)
  2468. (sauce :initarg :sauce :reader bad-tasting-sundae-sauce)
  2469. (topping :initarg :topping :reader bad-tasting-sundae-topping))
  2470. (:report (lambda (condition stream)
  2471. (format stream "Bad tasting sundae with ~S, ~S, and ~S"
  2472. (bad-tasting-sundae-ice-cream condition)
  2473. (bad-tasting-sundae-sauce condition)
  2474. (bad-tasting-sundae-topping condition)))))
  2475. \EV BAD-TASTING-SUNDAE
  2476. (defun all-start-with-same-letter (symbol1 symbol2 symbol3)
  2477. (let ((first-letter (char (symbol-name symbol1) 0)))
  2478. (and (eql first-letter (char (symbol-name symbol2) 0))
  2479. (eql first-letter (char (symbol-name symbol3) 0)))))
  2480. \EV ALL-START-WITH-SAME-LETTER
  2481. (defun read-new-value ()
  2482. (format t "Enter a new value: ")
  2483. (multiple-value-list (eval (read))))
  2484. \EV READ-NEW-VALUE\eject
  2485. (defun verify-or-fix-perfect-sundae (ice-cream sauce topping)
  2486. (do ()
  2487. ((all-start-with-same-letter ice-cream sauce topping))
  2488. (restart-case
  2489. (error 'bad-tasting-sundae
  2490. :ice-cream ice-cream
  2491. :sauce sauce
  2492. :topping topping)
  2493. (use-new-ice-cream (new-ice-cream)
  2494. :report "Use a new ice cream."
  2495. :interactive read-new-value
  2496. (setq ice-cream new-ice-cream))
  2497. (use-new-sauce (new-sauce)
  2498. :report "Use a new sauce."
  2499. :interactive read-new-value
  2500. (setq sauce new-sauce))
  2501. (use-new-topping (new-topping)
  2502. :report "Use a new topping."
  2503. :interactive read-new-value
  2504. (setq topping new-topping))))
  2505. (values ice-cream sauce topping))
  2506. \EV VERIFY-OR-FIX-PERFECT-SUNDAE
  2507. (verify-or-fix-perfect-sundae 'vanilla 'caramel 'cherry)
  2508. \OUT Error: Bad tasting sundae with VANILLA, CARAMEL, and CHERRY.
  2509. \OUT To continue, type :CONTINUE followed by an option number:
  2510. \OUT 1: Use a new ice cream.
  2511. \OUT 2: Use a new sauce.
  2512. \OUT 3: Use a new topping.
  2513. \OUT 4: Return to Lisp Toplevel.
  2514. \OUT Debug> \IN{:continue 1}
  2515. \OUT Use a new ice cream.
  2516. \OUT Enter a new ice cream: \IN{'chocolate}
  2517. \EV CHOCOLATE, CARAMEL, CHERRY
  2518. \endcode
  2519. \label Side Effects:\None.
  2520. \label Affected By:\None.
  2521. \label Exceptional Situations:\None.
  2522. \label See Also::
  2523. \macref{restart-bind}, \macref{with-simple-restart}.
  2524. \label Notes::
  2525. \code
  2526. (restart-case \i{expression}
  2527. (\i{name1} \i{arglist1} ...\i{options1}... . \i{body1})
  2528. (\i{name2} \i{arglist2} ...\i{options2}... . \i{body2}))
  2529. \endcode
  2530. is essentially equivalent to
  2531. \code
  2532. (block #1=#:g0001
  2533. (let ((#2=#:g0002 nil))
  2534. (tagbody
  2535. (restart-bind ((name1 #'(lambda (&rest temp)
  2536. (setq #2# temp)
  2537. (go #3=#:g0003))
  2538. ...\i{slightly-transformed-options1}...)
  2539. (name2 #'(lambda (&rest temp)
  2540. (setq #2# temp)
  2541. (go #4=#:g0004))
  2542. ...\i{slightly-transformed-options2}...))
  2543. (return-from #1# \i{expression}))
  2544. #3# (return-from #1#
  2545. (apply #'(lambda \i{arglist1} . \i{body1}) #2#))
  2546. #4# (return-from #1#
  2547. (apply #'(lambda \i{arglist2} . \i{body2}) #2#)))))
  2548. \endcode
  2549. Unnamed restarts are generally only useful interactively
  2550. and an interactive option which has no description is of little value.
  2551. Implementations are encouraged to warn if
  2552. an unnamed restart is used and no report information
  2553. is provided
  2554. at compilation time.
  2555. At runtime, this error might be noticed when entering
  2556. the debugger. Since signaling an error would probably cause recursive
  2557. entry into the debugger (causing yet another recursive error, etc.) it is
  2558. suggested that the debugger print some indication of such problems when
  2559. they occur but not actually signal errors.
  2560. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2561. \code
  2562. (restart-case (signal fred)
  2563. (a ...)
  2564. (b ...))
  2565. \EQ
  2566. (restart-case
  2567. (with-condition-restarts fred
  2568. (list (find-restart 'a)
  2569. (find-restart 'b))
  2570. (signal fred))
  2571. (a ...)
  2572. (b ...))
  2573. \endcode
  2574. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2575. \endissue{DECLS-AND-DOC}
  2576. \endcom
  2577. %%% ========== RESTART-NAME
  2578. \begincom{restart-name}\ftype{Function}
  2579. \label Syntax::
  2580. \DefunWithValues restart-name {restart} {name}
  2581. \label Arguments and Values::
  2582. \param{restart}---a \term{restart}.
  2583. \param{name}---a \term{symbol}.
  2584. \label Description::
  2585. Returns the name of the \param{restart},
  2586. or \nil\ if the \param{restart} is not named.
  2587. \label Examples::
  2588. \code
  2589. (restart-case
  2590. (loop for restart in (compute-restarts)
  2591. collect (restart-name restart))
  2592. (case1 () :report "Return 1." 1)
  2593. (nil () :report "Return 2." 2)
  2594. (case3 () :report "Return 3." 3)
  2595. (case1 () :report "Return 4." 4))
  2596. \EV (CASE1 NIL CASE3 CASE1 ABORT)
  2597. ;; In the example above the restart named ABORT was not created
  2598. ;; explicitly, but was implicitly supplied by the system.
  2599. \endcode
  2600. \label Side Effects:\None.
  2601. \label Affected By:\None.
  2602. \label Exceptional Situations:\None.
  2603. \label See Also::
  2604. \funref{compute-restarts}
  2605. \funref{find-restart}
  2606. \label Notes:\None.
  2607. \endcom
  2608. %%% ========== WITH-CONDITION-RESTARTS
  2609. \begincom{with-condition-restarts}\ftype{Macro}
  2610. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2611. \label Syntax::
  2612. \DefmacWithValuesNewline with-condition-restarts
  2613. {condition-form restarts-form \starparam{form}}
  2614. {\starparam{result}}
  2615. \label Arguments and Values::
  2616. \param{condition-form}---a \term{form}; \term{evaluated} to produce a \param{condition}.
  2617. \param{condition}---a \term{condition} \term{object} resulting from the
  2618. \term{evaluation} of \param{condition-form}.
  2619. \param{restart-form}---a \term{form}; \term{evaluated} to produce a \param{restart-list}.
  2620. \param{restart-list}---a \term{list} of \term{restart} \term{objects} resulting
  2621. from the \term{evaluation} of \param{restart-form}.
  2622. \param{forms}---an \term{implicit progn}; \eval.
  2623. \param{results}---the \term{values} returned by \param{forms}.
  2624. \label Description::
  2625. First, the \param{condition-form} and \param{restarts-form} are \term{evaluated}
  2626. in normal left-to-right order; the \term{primary values} yielded by these
  2627. \term{evaluations} are respectively called the \param{condition}
  2628. and the \param{restart-list}.
  2629. Next, the \param{forms} are \term{evaluated} in a \term{dynamic environment}
  2630. in which each \term{restart} in \param{restart-list} is associated with
  2631. the \param{condition}. \Seesection\AssocRestartWithCond.
  2632. \label Examples:\None.
  2633. \label Side Effects:\None.
  2634. \label Affected By:\None.
  2635. \label Exceptional Situations:\None.
  2636. \label See Also::
  2637. \macref{restart-case}
  2638. \label Notes::
  2639. Usually this \term{macro} is not used explicitly in code,
  2640. since \macref{restart-case} handles most of the common cases
  2641. in a way that is syntactically more concise.
  2642. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2643. \endcom
  2644. %%% ========== WITH-SIMPLE-RESTART
  2645. \begincom{with-simple-restart}\ftype{Macro}
  2646. \label Syntax::
  2647. \DefmacWithValuesNewline with-simple-restart
  2648. {\paren{name format-control \starparam{format-argument}}
  2649. \starparam{form}}
  2650. {\starparam{result}}
  2651. \label Arguments and Values::
  2652. \param{name}---a \term{symbol}.
  2653. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  2654. \param{format-control}---a \term{format control}.
  2655. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  2656. \param{format-argument}---an \term{object} (\ie a \term{format argument}).
  2657. \param{forms}---an \term{implicit progn}.
  2658. \param{results}---in the normal situation,
  2659. the \term{values} returned by the \param{forms};
  2660. in the exceptional situation where the \term{restart} named \param{name} is invoked,
  2661. two values---\nil\ and \t.
  2662. \label Description::
  2663. \macref{with-simple-restart} establishes a restart.
  2664. If the restart designated by \param{name} is not invoked while executing \param{forms},
  2665. all values returned by the last of \param{forms} are returned.
  2666. If the restart designated by \param{name} is invoked,
  2667. control is transferred to \macref{with-simple-restart},
  2668. which returns two values, \nil\ and \t.
  2669. If \param{name} is \nil, an anonymous restart is established.
  2670. The \param{format-control} and \param{format-arguments} are used
  2671. report the \term{restart}.
  2672. \label Examples::
  2673. \code
  2674. (defun read-eval-print-loop (level)
  2675. (with-simple-restart (abort "Exit command level ~D." level)
  2676. (loop
  2677. (with-simple-restart (abort "Return to command level ~D." level)
  2678. (let ((form (prog2 (fresh-line) (read) (fresh-line))))
  2679. (prin1 (eval form)))))))
  2680. \EV READ-EVAL-PRINT-LOOP
  2681. (read-eval-print-loop 1)
  2682. (+ 'a 3)
  2683. \OUT Error: The argument, A, to the function + was of the wrong type.
  2684. \OUT The function expected a number.
  2685. \OUT To continue, type :CONTINUE followed by an option number:
  2686. \OUT 1: Specify a value to use this time.
  2687. \OUT 2: Return to command level 1.
  2688. \OUT 3: Exit command level 1.
  2689. \OUT 4: Return to Lisp Toplevel.
  2690. \endcode
  2691. \code
  2692. (defun compute-fixnum-power-of-2 (x)
  2693. (with-simple-restart (nil "Give up on computing 2{\hat}~D." x)
  2694. (let ((result 1))
  2695. (dotimes (i x result)
  2696. (setq result (* 2 result))
  2697. (unless (fixnump result)
  2698. (error "Power of 2 is too large."))))))
  2699. COMPUTE-FIXNUM-POWER-OF-2
  2700. (defun compute-power-of-2 (x)
  2701. (or (compute-fixnum-power-of-2 x) 'something big))
  2702. COMPUTE-POWER-OF-2
  2703. (compute-power-of-2 10)
  2704. 1024
  2705. (compute-power-of-2 10000)
  2706. \OUT Error: Power of 2 is too large.
  2707. \OUT To continue, type :CONTINUE followed by an option number.
  2708. \OUT 1: Give up on computing 2{\hat}10000.
  2709. \OUT 2: Return to Lisp Toplevel
  2710. \OUT Debug> \IN{:continue 1}
  2711. \EV SOMETHING-BIG
  2712. \endcode
  2713. \label Side Effects:\None.
  2714. \label Affected By:\None.
  2715. \label Exceptional Situations:\None.
  2716. \label See Also::
  2717. \macref{restart-case}
  2718. \label Notes::
  2719. \macref{with-simple-restart} is shorthand for one of the most
  2720. common uses of \macref{restart-case}.
  2721. \macref{with-simple-restart} could be defined by:
  2722. \issue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  2723. \code
  2724. (defmacro with-simple-restart ((restart-name format-control
  2725. &rest format-arguments)
  2726. &body forms)
  2727. `(restart-case (progn ,@forms)
  2728. (,restart-name ()
  2729. :report (lambda (stream)
  2730. (format stream ,format-control ,@format-arguments))
  2731. (values nil t))))
  2732. \endcode
  2733. \endissue{FORMAT-STRING-ARGUMENTS:SPECIFY}
  2734. Because the second return value is \t\ in the exceptional case,
  2735. it is common (but not required) to arrange for the second return value
  2736. in the normal case to be missing or \nil\ so that the two situations
  2737. can be distinguished.
  2738. \endcom
  2739. %-------------------- Pre-Defined Restarts --------------------
  2740. %%% ========== ABORT
  2741. \begincom{abort}\ftype{Restart}
  2742. \label Data Arguments Required::
  2743. None.
  2744. \label Description::
  2745. The intent of the \misc{abort} restart is to allow return to the
  2746. innermost ``command level.'' Implementors are encouraged to make
  2747. sure that there is always a restart named \funref{abort}
  2748. around any user code so that user code can call \funref{abort}
  2749. at any time and expect something reasonable to happen;
  2750. exactly what the reasonable thing is may vary somewhat. Typically,
  2751. in an interactive listener, the invocation of \funref{abort}
  2752. returns to the \term{Lisp reader} phase of the \term{Lisp read-eval-print loop},
  2753. though in some batch or multi-processing
  2754. situations there may be situations in which having it kill the running
  2755. process is more appropriate.
  2756. \label See Also::
  2757. \secref\Restarts,
  2758. {\secref\InterfacesToRestarts},
  2759. \funref{invoke-restart},
  2760. \funref{abort} (\term{function})
  2761. \endcom%{abort}
  2762. %%% ========== CONTINUE
  2763. \begincom{continue}\ftype{Restart}
  2764. \label Data Arguments Required::
  2765. None.
  2766. \label Description::
  2767. \Therestart{continue} is generally part of protocols where there is
  2768. a single ``obvious'' way to continue, such as in
  2769. \funref{break} and \funref{cerror}. Some
  2770. user-defined protocols may also wish to incorporate it for similar reasons.
  2771. In general, however, it is more reliable to design a special purpose restart
  2772. with a name that more directly suits the particular application.
  2773. \label Examples::
  2774. \code
  2775. (let ((x 3))
  2776. (handler-bind ((error #'(lambda (c)
  2777. (let ((r (find-restart 'continue c)))
  2778. (when r (invoke-restart r))))))
  2779. (cond ((not (floatp x))
  2780. (cerror "Try floating it." "~D is not a float." x)
  2781. (float x))
  2782. (t x)))) \EV 3.0
  2783. \endcode
  2784. \label See Also::
  2785. \secref\Restarts,
  2786. {\secref\InterfacesToRestarts},
  2787. \funref{invoke-restart},
  2788. \funref{continue} (\term{function}),
  2789. \macref{assert},
  2790. \funref{cerror}
  2791. \endcom%{continue}
  2792. %%% ========== MUFFLE-WARNING
  2793. \begincom{muffle-warning}\ftype{Restart}
  2794. \label Data Arguments Required::
  2795. None.
  2796. \label Description::
  2797. This \term{restart} is established by \funref{warn} so that \term{handlers}
  2798. of \typeref{warning} \term{conditions} have a way to tell \funref{warn}
  2799. that a warning has already been dealt with and that no further action is warranted.
  2800. \label Examples::
  2801. \code
  2802. (defvar *all-quiet* nil) \EV *ALL-QUIET*
  2803. (defvar *saved-warnings* '()) \EV *SAVED-WARNINGS*
  2804. (defun quiet-warning-handler (c)
  2805. (when *all-quiet*
  2806. (let ((r (find-restart 'muffle-warning c)))
  2807. (when r
  2808. (push c *saved-warnings*)
  2809. (invoke-restart r)))))
  2810. \EV CUSTOM-WARNING-HANDLER
  2811. (defmacro with-quiet-warnings (&body forms)
  2812. `(let ((*all-quiet* t)
  2813. (*saved-warnings* '()))
  2814. (handler-bind ((warning #'quiet-warning-handler))
  2815. ,@forms
  2816. *saved-warnings*)))
  2817. \EV WITH-QUIET-WARNINGS
  2818. (setq saved
  2819. (with-quiet-warnings
  2820. (warn "Situation #1.")
  2821. (let ((*all-quiet* nil))
  2822. (warn "Situation #2."))
  2823. (warn "Situation #3.")))
  2824. \OUT Warning: Situation #2.
  2825. \EV (#<SIMPLE-WARNING 42744421> #<SIMPLE-WARNING 42744365>)
  2826. (dolist (s saved) (format t "~&~A~%" s))
  2827. \OUT Situation #3.
  2828. \OUT Situation #1.
  2829. \EV NIL
  2830. \endcode
  2831. \label See Also::
  2832. \secref\Restarts,
  2833. {\secref\InterfacesToRestarts},
  2834. \funref{invoke-restart},
  2835. \funref{muffle-warning} (\term{function}),
  2836. \funref{warn}
  2837. \endcom%{muffle-warning}
  2838. %%% ========== STORE-VALUE
  2839. \begincom{store-value}\ftype{Restart}
  2840. \label Data Arguments Required::
  2841. a value to use instead (on an ongoing basis).
  2842. \label Description::
  2843. \Therestart{store-value} is generally used by \term{handlers}
  2844. trying to recover from errors of \term{types} such as \typeref{cell-error}
  2845. or \typeref{type-error}, which may wish to supply a replacement datum to
  2846. be stored permanently.
  2847. \label Examples::
  2848. \code
  2849. (defun type-error-auto-coerce (c)
  2850. (when (typep c 'type-error)
  2851. (let ((r (find-restart 'store-value c)))
  2852. (handler-case (let ((v (coerce (type-error-datum c)
  2853. (type-error-expected-type c))))
  2854. (invoke-restart r v))
  2855. (error ()))))) \EV TYPE-ERROR-AUTO-COERCE
  2856. (let ((x 3))
  2857. (handler-bind ((type-error #'type-error-auto-coerce))
  2858. (check-type x float)
  2859. x)) \EV 3.0
  2860. \endcode
  2861. \label See Also::
  2862. {\secref\Restarts},
  2863. {\secref\InterfacesToRestarts},
  2864. \funref{invoke-restart},
  2865. \funref{store-value} (\term{function}),
  2866. \macref{ccase},
  2867. \macref{check-type},
  2868. \macref{ctypecase},
  2869. \funref{use-value} (\term{function} and \term{restart})
  2870. \endcom%{store-value}
  2871. %%% ========== USE-VALUE
  2872. \begincom{use-value}\ftype{Restart}
  2873. \label Data Arguments Required::
  2874. a value to use instead (once).
  2875. \label Description::
  2876. \Therestart{use-value} is generally used by \term{handlers} trying
  2877. to recover from errors of \term{types} such as \typeref{cell-error},
  2878. where the handler may wish to supply a replacement datum for one-time use.
  2879. \label See Also::
  2880. {\secref\Restarts},
  2881. {\secref\InterfacesToRestarts},
  2882. \funref{invoke-restart},
  2883. \funref{use-value} (\term{function}),
  2884. \funref{store-value} (\term{function} and \term{restart})
  2885. \endcom%{use-value}
  2886. %%% ========== ABORT
  2887. %%% ========== CONTINUE
  2888. %%% ========== MUFFLE-WARNING
  2889. %%% ========== STORE-VALUE
  2890. %%% ========== USE-VALUE
  2891. \begincom{abort, continue, muffle-warning, store-value, use-value}\ftype{Function}
  2892. \idxref{abort}\idxref{continue}\idxref{muffle-warning}\idxref{store-value}\idxref{use-value}
  2893. \label Syntax::
  2894. %!!! KMP: Issue CONDITION-RESTARTS forgot to add the condition argument here,
  2895. % but I have added it tentatively (pending x3j13 approval) since I'm
  2896. % sure it was intended. (MUFFLE-WARNING-CONDITION-ARGUMENT was the technical
  2897. % issue that was raised to fix this, but it was never voted upon.)
  2898. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2899. \DefunNoReturn abort {{\opt} condition}
  2900. \DefunWithValues continue {{\opt} condition} {\nil}
  2901. \DefunNoReturn muffle-warning {{\opt} condition}
  2902. \DefunWithValues store-value {value {\opt} condition} {\nil}
  2903. \DefunWithValues use-value {value {\opt} condition} {\nil}
  2904. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2905. \label Arguments and Values::
  2906. \param{value}---an \term{object}.
  2907. \issue{MUFFLE-WARNING-CONDITION-ARGUMENT}
  2908. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2909. \param{condition}---a \term{condition} \term{object}, or \nil.
  2910. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2911. \endissue{MUFFLE-WARNING-CONDITION-ARGUMENT}
  2912. \label Description::
  2913. Transfers control to the most recently established \term{applicable restart}
  2914. having the same name as the function. That is,
  2915. \thefunction{abort} searches for an \term{applicable} \misc{abort} \term{restart},
  2916. \thefunction{continue} searches for an \term{applicable} \misc{continue} \term{restart},
  2917. and so on.
  2918. If no such \term{restart} exists,
  2919. the functions
  2920. \funref{continue},
  2921. \funref{store-value},
  2922. and \funref{use-value}
  2923. return \nil, and
  2924. the functions
  2925. \funref{abort}
  2926. and \funref{muffle-warning}
  2927. signal an error \oftype{control-error}.
  2928. \issue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2929. When \param{condition} is \term{non-nil},
  2930. only those \term{restarts} are considered that are
  2931. either explicitly associated with that \param{condition},
  2932. or not associated with any \term{condition};
  2933. that is, the excluded \term{restarts} are
  2934. those that are associated with a non-empty set of \term{conditions}
  2935. of which the given \param{condition} is not an \term{element}.
  2936. If \param{condition} is \nil, all \term{restarts} are considered.
  2937. \endissue{CONDITION-RESTARTS:PERMIT-ASSOCIATION}
  2938. \label Examples::
  2939. \code
  2940. ;;; Example of the ABORT retart
  2941. (defmacro abort-on-error (&body forms)
  2942. `(handler-bind ((error #'abort))
  2943. ,@forms)) \EV ABORT-ON-ERROR
  2944. (abort-on-error (+ 3 5)) \EV 8
  2945. (abort-on-error (error "You lose."))
  2946. \OUT Returned to Lisp Top Level.
  2947. ;;; Example of the CONTINUE restart
  2948. (defun real-sqrt (n)
  2949. (when (minusp n)
  2950. (setq n (- n))
  2951. (cerror "Return sqrt(~D) instead." "Tried to take sqrt(-~D)." n))
  2952. (sqrt n))
  2953. (real-sqrt 4) \EV 2
  2954. (real-sqrt -9)
  2955. \OUT Error: Tried to take sqrt(-9).
  2956. \OUT To continue, type :CONTINUE followed by an option number:
  2957. \OUT 1: Return sqrt(9) instead.
  2958. \OUT 2: Return to Lisp Toplevel.
  2959. \OUT Debug> \IN{(continue)}
  2960. \OUT Return sqrt(9) instead.
  2961. \EV 3
  2962. (handler-bind ((error #'(lambda (c) (continue))))
  2963. (real-sqrt -9)) \EV 3
  2964. ;;; Example of the MUFFLE-WARNING restart
  2965. (defun count-down (x)
  2966. (do ((counter x (1- counter)))
  2967. ((= counter 0) 'done)
  2968. (when (= counter 1)
  2969. (warn "Almost done"))
  2970. (format t "~&~D~%" counter)))
  2971. \EV COUNT-DOWN
  2972. (count-down 3)
  2973. \OUT 3
  2974. \OUT 2
  2975. \OUT Warning: Almost done
  2976. \OUT 1
  2977. \EV DONE
  2978. (defun ignore-warnings-while-counting (x)
  2979. (handler-bind ((warning #'ignore-warning))
  2980. (count-down x)))
  2981. \EV IGNORE-WARNINGS-WHILE-COUNTING
  2982. (defun ignore-warning (condition)
  2983. (declare (ignore condition))
  2984. (muffle-warning))
  2985. \EV IGNORE-WARNING
  2986. (ignore-warnings-while-counting 3)
  2987. \OUT 3
  2988. \OUT 2
  2989. \OUT 1
  2990. \EV DONE
  2991. ;;; Example of the STORE-VALUE and USE-VALUE restarts
  2992. (defun careful-symbol-value (symbol)
  2993. (check-type symbol symbol)
  2994. (restart-case (if (boundp symbol)
  2995. (return-from careful-symbol-value
  2996. (symbol-value symbol))
  2997. (error 'unbound-variable
  2998. :name symbol))
  2999. (use-value (value)
  3000. :report "Specify a value to use this time."
  3001. value)
  3002. (store-value (value)
  3003. :report "Specify a value to store and use in the future."
  3004. (setf (symbol-value symbol) value))))
  3005. (setq a 1234) \EV 1234
  3006. (careful-symbol-value 'a) \EV 1234
  3007. (makunbound 'a) \EV A
  3008. (careful-symbol-value 'a)
  3009. \OUT Error: A is not bound.
  3010. \OUT To continue, type :CONTINUE followed by an option number.
  3011. \OUT 1: Specify a value to use this time.
  3012. \OUT 2: Specify a value to store and use in the future.
  3013. \OUT 3: Return to Lisp Toplevel.
  3014. \OUT Debug> \IN{(use-value 12)}
  3015. \EV 12
  3016. (careful-symbol-value 'a)
  3017. \OUT Error: A is not bound.
  3018. \OUT To continue, type :CONTINUE followed by an option number.
  3019. \OUT 1: Specify a value to use this time.
  3020. \OUT 2: Specify a value to store and use in the future.
  3021. \OUT 3: Return to Lisp Toplevel.
  3022. \OUT Debug> \IN{(store-value 24)}
  3023. \EV 24
  3024. (careful-symbol-value 'a)
  3025. \EV 24
  3026. ;;; Example of the USE-VALUE restart
  3027. (defun add-symbols-with-default (default &rest symbols)
  3028. (handler-bind ((sys:unbound-symbol
  3029. #'(lambda (c)
  3030. (declare (ignore c))
  3031. (use-value default))))
  3032. (apply #'+ (mapcar #'careful-symbol-value symbols))))
  3033. \EV ADD-SYMBOLS-WITH-DEFAULT
  3034. (setq x 1 y 2) \EV 2
  3035. (add-symbols-with-default 3 'x 'y 'z) \EV 6
  3036. \endcode
  3037. \label Side Effects::
  3038. A transfer of control may occur if an appropriate \term{restart} is available,
  3039. or (in the case of \thefunction{abort} or \thefunction{muffle-warning})
  3040. execution may be stopped.
  3041. \label Affected By::
  3042. Each of these functions can be affected by
  3043. the presence of a \term{restart} having the same name.
  3044. \label Exceptional Situations::
  3045. If an appropriate \misc{abort} \term{restart}
  3046. is not available for \thefunction{abort},
  3047. or an appropriate \misc{muffle-warning} \term{restart}
  3048. is not available for \thefunction{muffle-warning},
  3049. an error \oftype{control-error} is signaled.
  3050. \label See Also::
  3051. \funref{invoke-restart},
  3052. {\secref\Restarts},
  3053. {\secref\InterfacesToRestarts},
  3054. \macref{assert},
  3055. \macref{ccase},
  3056. \funref{cerror},
  3057. \macref{check-type},
  3058. \macref{ctypecase},
  3059. \funref{use-value},
  3060. \funref{warn}
  3061. \label Notes::
  3062. \code
  3063. (abort condition) \EQ (invoke-restart 'abort)
  3064. (muffle-warning) \EQ (invoke-restart 'muffle-warning)
  3065. (continue) \EQ (let ((r (find-restart 'continue))) (if r (invoke-restart r)))
  3066. (use-value \param{x}) \EQ (let ((r (find-restart 'use-value))) (if r (invoke-restart r \param{x})))
  3067. (store-value x) \EQ (let ((r (find-restart 'store-value))) (if r (invoke-restart r \param{x})))
  3068. \endcode
  3069. No functions defined in this specification are required to provide
  3070. a \misc{use-value} \term{restart}.
  3071. \endcom