Copyright © 2003-2005, Peter Seibel
22. LOOP for Black Belts
In Chapter 7 I briefly discussed the extended **LOOP**
macro. As I mentioned then, **LOOP**
provides what is essentially a special-purpose language just for writing iteration constructs.
This might seem like a lot of bother—inventing a whole language just for writing loops. But if you think about the ways loops are used in programs, it actually makes a fair bit of sense. Any program of any size at all will contain quite a number of loops. And while they won’t all be the same, they won’t all be unique either; patterns will emerge, particularly if you include the code immediately preceding and following the loops—patterns of how things are set up for the loop, patterns in what gets done in the loop proper, and patterns in what gets done after the loop. The **LOOP**
language captures these patterns so you can express them directly.
The **LOOP**
macro has a lot of parts—one of the main complaints of **LOOP**
‘s detractors is that it’s too complex. In this chapter, I’ll tackle **LOOP**
head on, giving you a systematic tour of the various parts and how they fit together.