r7rs-small-texinfo

Unnamed repository; edit this file 'description' to name the repository.
git clone https://kaka.farm/~git/r7rs-small-texinfo
Log | Files | Refs | README | LICENSE

exception-handling.texinfo (1487B)


      1 @node Exception handling
      2 @subsection Exception handling
      3 
      4 @c TODO: Determine whether we can get the full form into the
      5 @c deffin without making it unreadable.
      6 @deffn syntax guard
      7 
      8 @display
      9 @code{(guard (}@svar{variable}
     10        @svar{cond clause1} @svar{cond clause2} @dots{}@code{)}
     11    @svar{body}@code{)}
     12 @end display
     13 
     14 Syntax: Each @svar{cond clause} is as in the specification of cond.
     15 
     16 Semantics: The @svar{body} is evaluated with an exception
     17 handler that binds the raised object (see @code{raise} in @ref{Exceptions})
     18 to @svar{variable} and, within the scope of
     19 that binding, evaluates the clauses as if they were the clauses of a
     20 @code{cond} expression. That implicit @code{cond} expression is evaluated with the
     21 continuation and dynamic environment of the @code{guard} expression. If every
     22 @svar{cond clause}'s @svar{test} evaluates to @code{#f} and there
     23 is no else clause, then
     24 @code{raise-continuable} is invoked on the raised object within the dynamic
     25 environment of the original call to @code{raise}
     26 or @code{raise-continuable}, except that the current
     27 exception handler is that of the @code{guard} expression.
     28 
     29 @xref{Exceptions} for a more complete discussion of exceptions.
     30 
     31 @lisp
     32 (guard (condition
     33          ((assq 'a condition) => cdr)
     34          ((assq 'b condition)))
     35   (raise (list (cons 'a 42))))
     36 @result{} 42
     37 
     38 (guard (condition
     39          ((assq 'a condition) => cdr)
     40          ((assq 'b condition)))
     41   (raise (list (cons 'b 23))))
     42 @result{} (b . 23)
     43 @end lisp
     44 
     45 @end deffn