1.1 About the Loop Facility

1.1.1 How the Loop Facility works

The driving element of the Loop Facility is theloop macro. For the sake of convenience, references to theloop macro that follow denote theloop macro as part of the Loop Facility, not the Common Lisploop macro. In discussions that concern the macro itself and not an extended construct,loop appears in boldface.

The evaluation of theloop macro occurs first through macro expansion. When Lisp encounters aloop macro call form, it invokes the Loop Facility and passes to it the loop clauses as a list of unevaluated forms, as with any macro. The loop clauses contain Common Lisp forms and loop keywords. The loop keywords are recognized by their symbol name, regardless of the packages that contain them. Theloop macro translates the given form into Common Lisp code and returns the expanded form.

The expanded loop form is one or more lambda expressions for the local binding of loop variables and a block and a tagbody that express a looping control structure. The expanded form consists of three basic parts in the tagbody:

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

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

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

Some clauses can be present only in the loop prologue; these clauses must come before other clauses that are in the main body of the loop form. Others can be present only in the loop epilogue. All other clauses are present in the final translated form in the same order given in the loop body.

Expansion of theloop macro produces an implicit block (namednil). Thus, the Common Lisp macroreturn and the special formreturn-from can be used to return values from a loop or to exit a loop.

The Loop Facility - 9 SEP 1996

Generated with Harlequin WebMaker