Loops
DSSSL doesn't have any construct that resembles the
for loop that occurs in most imperative languages like C
and Java. Instead, DSSSL employs a common trick in
functional languages for implementing a loop: tail recursion.
Loops in DSSSL use a special form of
let. This loop counts from 1 to 10:
(let ❶loopvar ❷((count 1))
❸(if (> count 10)
❹#t
(❺loopvar ❻(+ count 1))))
❶
This variable controls the loop. It is declared without an
initial value, immediately after the let
operand.
❷
Any number of additional local variables can be defined after
the loop variable, just as they can in any other
let expression.
❸
If you ever want the loop to end, you have to put some sort of a
test in it.
❹
This is the value that will be returned.
❺
Note that you iterate the loop by using the loop variable as if
it was a function name.
❻
The arguments to this function are the values that
you want the local variables declared in ❷ to have
in the next iteration.