Next: , Up: Clauses


2.1 Drivers

An iteration-driving clause conceptually causes the iteration to go forward. Driver clauses in iterate allow iteration over numbers, lists, vectors, hashtables, packages, files and streams. Iteration-driving clauses must appear at the top level of an iterate form; they cannot be nested inside another clause. The driver variable is updated at the point where the driver clause occurs. Before the clause is executed for the first time, the value of the variable is undefined.

Multiple drivers may appear in a single iterate form, in which case all of the driver variables are updated each time through the loop, in the order in which the clauses appear. The first driver to terminate will terminate the entire loop.

In all cases, the value of the driver variable on exit from the loop, including within the epilogue code (see the finally clause), is undefined.

All the parameters of a driver clause are evaluated once, before the loop begins. Hence it is not possible to change the bounds or other properties of an iteration by side-effect from within the loop.

With one exception, driver clauses begin with the word for (or the synonym as) and mention an iteration variable, which is given a binding within the iterate form. The exception is repeat, which just executes a loop a specified number of times:

— Clause: repeat n

Repeat the loop n times. For example:

       (iter (repeat 100)
             (print "I will not talk in class."))
  

If n <= 0 , then loop will never be executed. If n is not an integer, the actual number of executions will be ceil(n) .