for*steps variables with support for a small but useful subset of
forclause, which you can combine with any looping construct whatsoever. Simply wrap the looping construct with
for*and then call the local function
step*at the start of each loop body iteration. The first time
step*is called, the variables are initialized to their first value. On subsequent calls, the values are updated. The updates are always made in sequence, analogously to
setf. It is not semantically meaningful to read the variables before
step*has been called at least once.
for*deals with stepping of variables only. It never initiates a termination of looping. This is to avoid interfering with the semantics of the looping construct we're wrapping. If you find yourself wishing for such a feature, then simply make the termination test right at the start of the looping construct's body (right after the
step*call) and use any appropriate non-local exit construct.
Each binding in bindings is of the form
). Here are the supported stepping clauses:
- You can use
bylike you would with
upfromstart for incrementing from start,
downfromstart for decrementing. Use
bystep, a non-negative integer, to control the stepping (default is 1).
Here's an example of a
forbinding clause to create a local variable index that will successively take the values ‘10, 7, 4, 1, -2’, etc.:(index downfrom 10 by 3)
- You can use
thenlike you would with
loop. There are two possible forms of this statement:(var = form)
In this case, a binding var is created, and will be set to the value form evaluates to on each iteration. Note that it is stylistically inappropriate to use this form of stepping if there is no further
for*binding which needs to refer to the value of this variable. Use a more conventional binding construct such as
letinside the body of the loop instead.(var = first-form then then-form)
In this case, a binding var is created, and will be set to the value first-form evaluates to on the first iteration (the first time
step*is called), and then to the value then-form evaluates to on subsequent iterations.