DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(guile.info.gz) if cond case

Info Catalog (guile.info.gz) begin (guile.info.gz) Control Mechanisms (guile.info.gz) and or
 
 26.2 Simple Conditional Evaluation
 ==================================
 
 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.
 
  -- syntax: if test consequent [alternate]
      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 `#f', the
      value of the expression is not specified.
 
  -- syntax: cond clause1 clause2 ...
      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 `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.
 
      The TEST of the last CLAUSE may be the keyword `else'.  Then, if
      none of the preceding TESTs is true, the EXPRESSIONs following the
      `else' are evaluated to produce the result of the
      `cond'-expression.
 
  -- syntax: case key clause1 clause2 ...
      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 `case' expression.
 
      If the KEY matches no DATUM and there is an `else'-clause, the
      expressions following the `else' are evaluated.  If there is no
      such clause, the result of the expression is unspecified.
 
Info Catalog (guile.info.gz) begin (guile.info.gz) Control Mechanisms (guile.info.gz) and or
automatically generated byinfo2html