guard -- r7rs Definition syntax;
Syntax keywords:
variable: identifier;else: literal;clause-condition: expression;clause-expression: expression;clause: pattern with variants:
(clause-condition);(clause-condition clause-expression |...|);(else clause-expression |...|);guarded-expression: expression;Syntax variants:
(_ (variable clause |...|) guarded-expression |...|)scheme:base -- (scheme base);scheme -- (scheme);(guard (<variable> <cond-clause_1> <cond-clause_2> ...) <body>)Syntax: Each
<cond-clause>is as in the specification ofcond.Semantics: The
<body>is evaluated with an exception handler that binds the raised object (seeraisein section on exceptions) to<variable>and, within the scope of that binding, evaluates the clauses as if they were the clauses of acondexpression. That implicitcondexpression is evaluated with the continuation and dynamic environment of theguardexpression. If every<cond-clause>'s<test>evaluates to#fand there is no else clause, thenraise-continuableis invoked on the raised object within the dynamic environment of the original call toraiseorraise-continuable, except that the current exception handler is that of theguardexpression.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.