Common Lisp/External libraries/Iterate

Iterate provides an English language like iteration mechanism much like the Common Lisp LOOP facility. This raises the question - why use iterate when you have LOOP built in? The best reason for using Iterate is for its extensibility. LOOP is quite static, but Iterate can be extended to iterate over your own data structures, for instance.

Standard use
As you will see, the syntax of Iterate is very much like LOOP. In fact, it is often a good idea to think of Iterate as LOOP with parentheses. The parentheses are purely aesthetic. The main idea behind the parentheses is to provide hints to text editors for how the syntax should be formatted and to make it easier to write extensions.


 * FOR loops

For a list of all iterate constructs, use the function DISPLAY-ITERATE-CLAUSES.

Extending Iterates Functionality
In order to extend Iterate you need to write a new driver.

Iterate “gotchas”
Binding done by the iterate in the FOR driver is actually done via a SET. This means that you have to pay extra attention to these bound variables when you collect a series of closures. Unless you explicitly make a lexical binding, the closure will close over the variable that iterate is mutating. In the end, you will get a collection of closures that all have the binding that iterate exited on.

Don't do this:

Do this:

You should note that LOOP behaves the same way.