8.16.0.4
5.3 Guards
definition | |||||
|
Checks that test_expr produces a true value, evaluating the
body sequence if so. If test_expr produces
#false, then body is skipped and failure_body
is evaluated, instead. This is equivalent to
if $test_expr | $body ... | $failure_body ..., and is primarily
useful when body is much more complex than failure_body
or contains a mixture of definitions and additional guard forms
interleaved with each other.
Static information works the same way as it would in an equivalent if expression.
> block:
println("everything working normally")
everything working normally
> block:
println("everything working normally")
KABOOM!!!
definition | |||||||
| |||||||
| |||||||
definition | |||||||
|
Checks that target_expr produces a value that matches
test_bind and makes the bindings of test_bind
available in the subsequent body sequence. If
target_expr does not match test_bind, then the
body sequence is skipped and failure_body is
evaluated, instead. This is the pattern matching variant of
guard, see its documentation for general advice on using
guards.
> print_third(["hi", "hello", "goodbye", "farewell"])
goodbye
> print_third(["hi", "hello"])
list doesn't have three or more elements
The block form with target_body is equivalent to using block: target_body ... as the target_expr.
> print_third(["hi", "hello", "goodbye", "farewell"])
goodbye
> print_third(["hi", "hello"])
list doesn't have three or more elements