guard -- r7rs Definition
§

Kind
§

syntax;

Implemented by
§

Syntax signature
§

Syntax keywords:

Syntax variants:

Exports
§

Exports recursive
§

Description
§

(guard (<variable>
        <cond-clause_1> <cond-clause_2> ...)
    <body>)

Syntax: Each <cond-clause> is as in the specification of cond.

Semantics: The <body> is evaluated with an exception handler that binds the raised object (see raise in section on exceptions) to <variable> and, within the scope of that binding, evaluates the clauses as if they were the clauses of a cond expression. That implicit cond expression is evaluated with the continuation and dynamic environment of the guard expression. If every <cond-clause>'s <test> evaluates to #f and there is no else clause, then raise-continuable is invoked on the raised object within the dynamic environment of the original call to raise or raise-continuable, except that the current exception handler is that of the guard expression.

See section on exceptions for a more complete discussion of exceptions.

(guard (condition
         ((assq 'a condition) => cdr)
         ((assq 'b condition)))
  (raise (list (cons 'a 42))))
===> 42

(guard (condition
         ((assq 'a condition) => cdr)
         ((assq 'b condition)))
  (raise (list (cons 'b 23))))
===> (b . 23)

The text herein was sourced and adapted as described in the "R7RS attribution of various text snippets" appendix.