for*
for*steps variables with support for a small but useful subset ofloop'sforclause, which you can combine with any looping construct whatsoever. Simply wrap the looping construct withfor*and then call the local functionstep*at the start of each loop body iteration. The first timestep*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 tolet*andsetf. It is not semantically meaningful to read the variables beforestep*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 thestep*call) and use any appropriate non-local exit construct.Each binding in bindings is of the form
(var.stepping). Here are the supported stepping clauses:
- for-as-arithmetic
- You can use
from,upfrom,downfromandbylike you would withloop:fromstart orupfromstart for incrementing from start,downfromstart for decrementing. Usebystep, 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)- for-as-equals
- You can use
=andthenlike you would withloop. 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 asletinside 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.