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 1loopvar 2((count 1))
  3(if (> count 10)
    4#t
    (5loopvar 6(+ count 1))))

1

This variable controls the loop. It is declared without an initial value, immediately after the let operand.

2

Any number of additional local variables can be defined after the loop variable, just as they can in any other let expression.

3

If you ever want the loop to end, you have to put some sort of a test in it.

4

This is the value that will be returned.

5

Note that you iterate the loop by using the loop variable as if it was a function name.

6

The arguments to this function are the values that you want the local variables declared in 2 to have in the next iteration.