Next: , Previous: , Up: Loop   [Contents][Index]


15.25.2 How the Loop Facility Works

Loop Macro

The driving element of the Loop Facility is the loop macro.

When Lisp encounters a loop macro call form, it

Loop Clauses

The loop clauses contain

Expanded Loop Form

The expanded loop form is

Variables

The variables established in the loop construct are bound as if by using let or lambda. Implementations can interleave the setting of initial values with the bindings. However, the assignment of the initial values is always calculated in the order specified by the user. A variable is thus sometimes bound to a harmless value of the correct data type, and then later in the prologue it is set to the true initial value by using setq.

Parts of the Expanded Form

The expanded form consists of three basic parts in the tagbody:

Loop Prologue

contains forms that are executed before iteration begins, such as initial settings of loop variables and possibly an initial termination test.

Loop Body

contains those forms that are executed during iteration, including application-specific calculations, termination tests, and variable stepping. Stepping is the process of assigning a variable the next item in a series of items.

Loop Epilogue

contains forms that are executed after iteration terminates, such as code to return values from the loop.

nil Block—returnreturn-from

Expansion of the loop macro produces an implicit block (named ‘nil’). Thus, the Common Lisp macro return and the special form return-from can be used to return values from a loop or to exit a loop.

Within the executable parts of loop clauses and around the entire loop form, you can still bind variables by using the Common Lisp special form let.


Next: Parsing Loop Clauses, Previous: Introduction, Up: Loop   [Contents][Index]