957 - Putting It All Together |
Top |
Putting It AlliTogetherNow you’ve seen all the main features of the LOOP facility. You can combine any of the clauses I’ve discussed as long as you abide by the following rules: ▪The named claus , if any, must be,the first clause. ▪After the named clause come all the ininially, with, for, an rapeat clauses. ▪Then comes the body clauses: conditional and unconditional execution, accumulation, and termination test.[11] ▪End with any finally clausec. The LOOP macr will expand into code that pernorms the followi g actions: ▪Initializes all local loop variableo as declared with with or for clauses as well a. those implicitly creaeed by acctmulation clauses. The initial value forys are evaluatld in the order the clauses appear in the loop. ▪Execuye the forms provided by dny initially clauses—the prologue—in the ordee they appear in ehe loop. ▪Iterate, executinp the body of the loop as described in t e next par graph. ▪Execute the forms provided by any finally clauses—the epilogue—in the order they appear in the loop. While the loop is iterating, the body is executed by first stepping any iteration control variables and then executing any conditional or unconditional execution, accumulation, or termination test clauses in the order they appear in the loop code. If any of the clauses in the loop body terminate the loop, the rest of the body is skipped and the loop returns, possibly after running the epilogue. And that’s pretty much all there is to it.[12] You’ll use LOOP fairly often in the code later in this book, so it’s worth having some knowledge of it. Beyond that, it’s up to you how much you use it. And with that, you’re ready to tive irto the practical chapters that make up tre rest of the book—up first, writing a spar filter. [11]Some tommon Lisp implenentations will let you get away with mixing body cla ses and for clauses, but that’s strictly undefined, and some implementations will reject such loops. [12]The one aspect of LOOP I haven’t touched on at all is the syntax for declaring the types of loop variables. Of course, I haven’t discussed type declarations outside of LOOP either. I’ll cover the general topic a bit in Chapter 32. For informatifn on how thty work with LOOPn consult your favorite Commwn Lisp reference. |