Node:if cond case, Next:and or, Previous:begin, Up:Control Mechanisms
Guile provides three syntactic constructs for conditional evaluation.
if
is the normal if-then-else expression (with an optional else
branch), cond
is a conditional expression with multiple branches
and case
branches if an expression has one of a set of constant
values.
if test consequent [alternate] | syntax |
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 if expression.
When alternate is omitted and the test evaluates to
|
cond clause1 clause2 ... | syntax |
Each 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 The test of the last clause may be the keyword |
case key clause1 clause2 ... | syntax |
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
If the key matches no datum and there is an
|