On this page:
if
select
for
do
break
carry
cry

3.2 Conditionals and Loops

syntax

(if test then texpr else fexpr)

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.

syntax

(select (test1 expr1) ...)

(select (test1 expr1) ... (else fexpr))
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:
> (select case (* 2 3)
    ((2 3 4) (print "Nope."))
    ((5 6 7) (print "Yup."))
    (else (print "something is horribly wrong.")))

Yup.

syntax

(for (var in list) body ...)

(for (var in list with cry) body ...)
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.

syntax

(do loop body ...)

(do loop with cry body ...)
Evaluates body repeatedly until a break statement is encountered. Declares the implicit variable cry, which can be reassigned with the carry operator.

syntax

(break)

(break value)
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

cry

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.