3.2 Conditionals and Loops
Evalutes test and, if test is True
, evaluates
texpr, otherwise it evaluates fexpr. Note that only a single
expression can be placed in each "slot" in the syntax; if you need to do
multiple things, use a do block.
Given a list of test-expression pairs, evaluates the tests in order until it
finds one which is True, and evaluates the matching expression. The
else expression is always true: if an else is found at the end of the
select statement, its matching fexpr will be evaluated. If no test in
select is true, returns #<void>.
syntax
(select case texpr ((val ...) rexpr) ...)
(select case texpr ((val ...) rexpr) ... (else fexpr))
Evaluates texpr and compares it to each val in turn until it
finds a value that is eq? to the result of texpr. If one is
found, it evaluates the matching rexpr. Like with select,
else is always considered True, and will therefore always evaluate its
fexpr. If no matching val is found, select case
evaluates to #<void>. Note also that the (val ...) is a list, and
can contain as many values as is needed, such as in the following example:
Example:
Iterates over list evaluating its body with the head of list assigned to var,
then recurs with the tail of list until it returns Null. for
loops declare an implicit variable cry which can be passed a value with
carry. They may also be interrupted with break. See below for
more details.
syntax
(do body ...)
Evaluates its bodys in order, returning the result of the final body
expression.
Evaluates body repeatedly until a break statement is encountered.
Declares the implicit variable cry, which can be reassigned with the
carry operator.
Breaks the continuation of a for or do loop evaluation. If
provided a value, returns that value as the result of the loop.
syntax
(carry value)
When called in the body of a for or do loop expression,
immediately begins the next iteration of the loop, and passes the given value to
the implicit variable cry.
syntax
Loops declare an internal variable called cry, which defaults to
Null, and which is passed automatically to the next iteration of the
loop, and is returned when the loop concludes. The value of cry can be
specified at the beginning of the loop with the optional with
parameter, and carry can be used to pass a new value of cry to
the next iteration.