Guile provides three syntactic constructs for conditional evaluation.
if is the normal if-then-else expression (with an optional else
cond is a conditional expression with multiple branches
case branches if an expression has one of a set of constant
All arguments may be arbitrary expressions. First, test is evaluated. If it returns a true value, the expression consequent is evaluated and alternate is ignored. If test evaluates to
#f, alternate is evaluated instead. The value of the evaluated branch (consequent or alternate) is returned as the value of the
When alternate is omitted and the test evaluates to
#f, the value of the expression is not specified.
cond-clause must look like this:(test expression ...)
where test and expression are arbitrary expression, or like this(test => expression)
where expression must evaluate to a procedure.
The tests of the clauses are evaluated in order and as soon as one of them evaluates to a true values, the corresponding expressions are evaluated in order and the last value is returned as the value of the
cond-expression. For the
=>clause type, expression is evaluated and the resulting procedure is applied to the value of test. The result of this procedure application is then the result of the
cond-expression.(test guard => expression)
where guard and expression must evaluate to procedures. For this clause type, test may return multiple values, and
condignores its boolean state; instead,
condevaluates guard and applies the resulting procedure to the value(s) of test, as if guard were the consumer argument of
call-with-values. Iff the result of that procedure call is a true value, it evaluates expression and applies the resulting procedure to the value(s) of test, in the same manner as the guard was called.
The test of the last clause may be the symbol
else. Then, if none of the preceding tests is true, the expressions following the
elseare evaluated to produce the result of the
key may be any expression, the clauses must have the form((datum1 ...) expr1 expr2 ...)
and the last clause may have the form(else expr1 expr2 ...)
All datums must be distinct. First, key is evaluated. The the result of this evaluation is compared against all datums using
eqv?. When this comparison succeeds, the expression(s) following the datum are evaluated from left to right, returning the value of the last expression as the result of the
If the key matches no datum and there is an
else-clause, the expressions following the
elseare evaluated. If there is no such clause, the result of the expression is unspecified.