minor layout change
[clqr.git] / clqr-control-structure.tex
blob154e77db7cbab580b86844f8a773202cf76f2388
1 % Copyright (C) 2008 Bert Burgemeister
3 % Permission is granted to copy, distribute and/or modify this
4 % document under the terms of the GNU Free Documentation License,
5 % Version 1.2 or any later version published by the Free Software
6 % Foundation; with no Invariant Sections, no Front-Cover Texts and
7 % no Back-Cover Texts. For details see file COPYING.
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11 \section{Control Structure}
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15 \subsection{Predicates}
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17 \begin{LIST}{1cm}
19 \IT{(\FU*{EQ} \VAR{foo bar})}
21 \retval{\T} if \VAR{foo} and \VAR{bar} are identical.
24 \IT{(\FU*{EQL} \VAR{foo bar})}
26 \retval{\T} if \VAR{foo} and \VAR{bar}
27 are identical, or the same character, or the same number.
30 \IT{(\FU*{EQUAL} \VAR{foo bar})}
32 \retval{\T} if \VAR{foo} and \VAR{bar}
33 are \FU{EQL}, or are conses with \FU{equal} cars and cdrs, or are
34 strings or bit-vectors with \FU{eql} elements, or are equivalent pathnames.
37 \IT{(\FU*{EQUALP} \VAR{foo bar})}
39 \retval{\T} if \VAR{foo} and \VAR{bar}
40 are \FU{EQUAL}, or if they have corresponding components of the same
41 type which are \FU{equalp}.
44 \IT{(\FU*{NOT} \VAR{bool})}
46 \retval{\NIL} if \VAR{bool} is \T; \retval{\T} if \VAR{bool} is \NIL.
49 \IT{(\FU*{BOUNDP} \VAR{symbol})}
51 \retval{\T} if \VAR{symbol} is a special variable.
54 \IT{(\FU*{CONSTANTP} \VAR{foo} \Op{\VAR{environment}})}
56 \retval{\T} if \VAR{foo} is a constant form.
59 \IT{(\FU*{FUNCTIONP} \VAR{foo})}
61 \retval{\T} if \VAR{foo} is of type \kwd{function}.
64 \IT{(\FU*{FBOUNDP} \VAR{foo})}
66 \retval{\T} if \VAR{foo} is a global function or macro.
70 \end{LIST}
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 \subsection{Variables}
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 \begin{LIST}{1cm}
79 \IT{(\kwd*{DEFVAR} \VAR{name} \OP{\VAR{form}
80 \Op{\VAR{documentation}}})}
82 Unless bound already, assign value of \VAR{form} to dynamic variable
83 \retval{\VAR{name}}.
86 \IT{(\kwd*{DEFPARAMETER} \VAR{name} \VAR{form}
87 \Op{\VAR{documentation}})}
89 Assign value of \VAR{form} to dynamic variable \retval{\VAR{name}}.
92 \IT{(\kwd*{DEFCONSTANT} \VAR{name} \VAR{form}
93 \Op{\VAR{documentation}})}
95 Assign value of \VAR{form} to global constant \retval{\VAR{name}}.
98 \IT{(\xorGOO{\SF*{SETF}\\
99 \SF*{PSETF}}{\}} \Goos{\VAR{place}
100 \VAR{form}})}
102 Set \VAR{place}s to values of \VAR{form}s returning \retval{value
103 of last \VAR{form}}. Work sequentially/in parallel, respectively.
106 \IT{(\xorGOO{\SF*{SETQ}\\
107 \SF*{PSETQ}}{\}} \Goos{\VAR{symbol}
108 \VAR{form}})}
110 Set \VAR{symbol}s to values of \VAR{form}s returning \retval{value
111 of last \VAR{form}}. Work sequentially/in parallel, respectively.
114 \IT{(\FU*{SET} \VAR{symbol} \VAR{foo})}
116 Set \VAR{symbol}'s value cell to \retval{\VAR{foo}}.
119 \IT{(\SF*{MULTIPLE-VALUE-SETQ} \VAR{vars} \VAR{form})}
121 Set elements of \VAR{vars} to the values of
122 \VAR{form}. Return \retval{\VAR{form}'s primary value}.
125 \IT{(\SF*{SHIFTF} \RP{\VAR{place}} \VAR{foo})}
127 Store valueof \VAR{foo} in rightmost \VAR{place} shifting values of
128 \VAR{place}s left, returning \retval{first \VAR{place}}.
131 \IT{(\SF*{ROTATEF} \OPn{\VAR{place}})}
133 Rotate values of \VAR{place}s left, old first becoming new last
134 \VAR{place}'s value. Return \retval{\NIL}.
137 \IT{(\FU*{MAKUNBOUND} \VAR{symbol})}
139 Delete special variable \retval{\VAR{symbol}}.
142 \label{:property_lists}
143 \IT{\arrGOO{(\FU*{GET} \VAR{ symbol} \VAR{ key }
144 \OP{\VAR{default}\DF{\NIL}})\\
145 (\FU*{GETF} \VAR{ place} \VAR{ key }
146 \OP{\VAR{default}\DF{\NIL}})}{.}}
148 \retval{First entry \VAR{key}} from property list stored in
149 \VAR{symbol}/in \VAR{place}, respectively, or \retval{\VAR{default}} if
150 there was no \VAR{key}. \kwd{setf}able.
153 \IT{(\FU*{GET-PROPERTIES} \VAR{property-list} \VAR{keys})}
155 Return \retval{key} and \retvalii{value} of first entry from \VAR{property-list}
156 matching a key from \VAR{keys}, and \retvaliii{tail of
157 \VAR{property-list}} starting with that key. Return \retval{\NIL},
158 \retvalii{\NIL}, and \retvaliii{\NIL} if there was no matching key
159 in \VAR{property-list}.
162 \IT{\arrGOO{(\FU*{REMPROP} \VAR{ symbol} \VAR{ key})\\
163 (\SF*{REMF} \VAR{ place} \VAR{ key})}{.}}
165 Remove fist entry \VAR{key} from property list stored in
166 \VAR{symbol}/in \VAR{place}, respectively. Return \retval{\T} if \VAR{key}
167 was there, or \retval{\NIL} otherwise.
170 \end{LIST}
173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 \subsection{Functions}
175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 \label{section:Functions}
179 \begin{flushleft}
180 Below, lambda list (\OPn{\VAR{fu-arg}}) has the form\\
181 (\OPn{\VAR{var}}
182 \OP{\kwd*{\&optional} \Goos{\VAR{var}\XOR(\VAR{var} \OP{\VAR{init}
183 \Op{\VAR{supplied-p}}})}}
184 \Op{\kwd*{\&rest} \VAR{var}}
185 \OP{\kwd*{\&key} \GOos{\VAR{var}\XOR(\Goo{\VAR{var}\XOR(\kwd{:}\VAR{key}
186 \VAR{var})}
187 \OP{\VAR{init }\Op{\VAR{supplied-p}}})}
188 \Op{\kwd*{\&allow-other-keys}}}
189 \OP{\kwd*{\&aux} \Goos{\VAR{var}\XOR(\VAR{var} \Op{\VAR{init}})}}).\\
190 \VAR{supplied-p} is \T\ if there is a corresponding argument.
191 \end{flushleft}
193 \begin{LIST}{1cm}
195 \IT{(\xorGOO{\SF*{DEFUN} \VAR{ foo}\\ \SF*{LAMBDA}}{\}}
196 (\VAR{\OPn{fu-arg}}) \OPn{(\kwd{declare} \OPn{\VAR{decl}})}
197 \Op{\VAR{documentation}}
198 \OPn{\VAR{form}})}
200 Define function with \retval{name \VAR{foo}} or an anonymous
201 function, respectively, which
202 applies \VAR{form}s to \VAR{fu-arg}s.
205 \IT{(\xorGOO{\SF*{FLET}\\
206 \SF*{LABELS}}{\}}
207 (\OPn{(\VAR{foo}
208 (\OPn{\VAR{fu-arg}})
209 \OPn{(\kwd{declare} \OPn{\VAR{local-decl}})}%
210 \Op{\VAR{documentation}}
211 \OPn{\VAR{local-form}})}) \OPn{(\kwd{declare} \VAR{decl})}
212 \OPn{\VAR{form}})}
214 Evaluate \VAR{form}s with
215 locally defined functions \VAR{foo}. Only for \SF{LABELS},
216 \VAR{foo}s are visible inside \VAR{local-forms}. Return
217 \retval{values of \VAR{form}s}.
220 \IT{(\SF*{FUNCTION} \VAR{foo})}
221 {Return \retval{function named \VAR{foo}}.
224 \IT{(\FU*{APPLY} \VAR{function} \RP{\VAR{arg}})}
226 Return \retval{value of \VAR{function}} called on
227 \VAR{arg}s. Last \VAR{arg} must be a list.
230 \IT{(\FU*{FUNCALL} \VAR{function} \OPn{arg})}
232 Return \retval{value of \VAR{function}} called with \VAR{arg}s.
235 \IT{(\SF*{MULTIPLE-VALUE-CALL} \VAR{foo} \OPn{\VAR{form}})}
236 {Call function
237 \VAR{foo} with values of \VAR{form}s as its arguments. Return
238 \retval{values returned by \VAR{foo}}.
241 \IT{(\FU*{VALUES-LIST} \VAR{list})}
243 Return \retval{elements of \VAR{list}}.
246 \IT{(\FU*{VALUES} \OPn{\VAR{foo}})}
248 Return \retval{\VAR{foo}s} as multiple values. \kwd{setf}able.
251 \IT{(\FU*{MULTIPLE-VALUE-LIST} \VAR{form})}
253 Return in a \retval{list} values of \VAR{form}.
256 \IT{(\FU*{NTH-VALUE} \VAR{n} \VAR{form})}
258 Zero-indexed \retval{\VAR{n}th return value} of \VAR{form}.
261 \IT{(\FU*{COMPLEMENT} \VAR{function})}
263 Return \retval{new function} with same arguments and same side effects
264 as \VAR{function}, but with complementary truth value.
267 \IT{(\FU*{CONSTANTLY} \VAR{foo})}
269 Return \retval{function} of any number of arguments returning \VAR{foo}.
272 \IT{(\FU*{IDENTITY} \VAR{foo})}
274 Return \retval{\VAR{foo}}.
277 \IT{(\FU*{FUNCTION-LAMBDA-EXPRESSION} \VAR{function})}
279 If available, return \retval{lambda expression} of \VAR{function},
280 \retvalii{\NIL} if \VAR{function} was defined in an environment
281 without bindings, and \retvaliii{name} of \VAR{function}.
284 \IT{(\FU*{FDEFINITION} \VAR{foo})}
286 \retval{Definition} of function \VAR{foo}. \kwd{setf}able.
289 \IT{(\FU*{FMAKUNBOUND} \VAR{foo})}
291 Remove global function or macro definition \retval{\VAR{foo}}.
294 \IT{\arrGOO{\CNS*{CALL-ARGUMENTS-LIMIT}\\
295 \CNS*{LAMBDA-PARAMETERS-LIMIT}}{.}}
297 Upper bound of the number of function arguments or lambda list
298 parameters, respectively; $\geq50$.
301 \IT{\CNS*{MULTIPLE-VALUES-LIMIT}}
303 Upper bound of the number of values a function can return; $\geq20$.
306 \end{LIST}
309 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 \subsection{Macros}
311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 \begin{flushleft}
314 Below, macro lambda list (\OPn{\VAR{macro-arg}}) has the form of either\\
315 (\Op{\kwd*{\&whole} \VAR{var}}
316 \Op{\kwd*{\&environment} \VAR{var}}
317 \OPn{\VAR{var}}
318 \Op{\kwd*{\&environment} \VAR{var}}
319 \Op{\kwd*{\&optional} \Goos{\VAR{var}\XOR(\VAR{var} \OP{\VAR{init}
320 \Op{\VAR{supplied-p}}})}}
321 \Op{\kwd*{\&environment} \VAR{var}}
322 \Op{\Goo{\kwd*{\&rest}\XOR\kwd*{\&body}} \VAR{var}}
323 \Op{\kwd*{\&environment} \VAR{var}}
324 \OP{\kwd*{\&key} \GOos{\VAR{var}\XOR(\Goo{\VAR{var}\XOR(\kwd{:}\VAR{key}
325 \VAR{var})}
326 \OP{\VAR{init} \Op{\VAR{supplied-p}}})}
327 \Op{\kwd*{\&environment} \VAR{var}}
328 \Op{\kwd*{\&allow-other-keys}}}
329 \Op{\kwd*{\&aux} \Goos{\VAR{var}\XOR(\VAR{var} \Op{\VAR{init}})}}
330 \Op{\kwd*{\&environment} \VAR{var}})\\
331 or\\
332 (\Op{\kwd*{\&whole} \VAR{var}}
333 \Op{\kwd*{\&environment} \VAR{var}}
334 \OPn{\VAR{var}}
335 \Op{\kwd*{\&environment} \VAR{var}}
336 \Op{\kwd*{\&optional} \Goos{\VAR{var}\XOR(\VAR{var} \OP{\VAR{init}
337 \Op{\VAR{supplied-p}}})}}
338 \Op{\kwd*{\&environment} \VAR{var}}
339 \kwd{.} \VAR{var}).\\
340 \kwd*{\&environment} \VAR{var} may appear only once.
341 \VAR{supplied-p} is \T\ if there is a corresponding argument.
342 \end{flushleft}
344 \begin{LIST}{1cm}
346 \IT{(\xorGOO{\SF*{DEFMACRO}\\\FU*{DEFINE-COMPILER-MACRO}}{\}}
347 \VAR{foo} (\OPn{\VAR{macro-arg}})
348 \OPn{(\kwd{declare} \OPn{\VAR{decl}})} \Op{\VAR{documentation}}
349 \OPn{\VAR{form}})}
351 Define macro \retval{\VAR{foo}}.
354 \IT{(\SF*{DEFINE-SYMBOL-MACRO} \VAR{name} \VAR{expansion-form})}
356 Make \retval{\VAR{name}} a macro call.
359 \IT{(\SF*{MACROLET} (\OPn{(\VAR{name} (\OPn{\VAR{macro-arg}})
360 \OPn{(\kwd{declare} \OPn{\VAR{local-decl}})}
361 \Op{\VAR{documentation}} \OPn{\VAR{macro-form}})}) \OPn{(\kwd{declare}
362 \OPn{\VAR{decl}})} \OPn{\VAR{form}})}
364 Evaluate \retval{\VAR{form}s} with \VAR{name}s locally defined
365 as macros which are invisible to each other.
368 \IT{(\SF*{SYMBOL-MACROLET} (\OPn{(\VAR{name}
369 \VAR{expansion-form})}) \OPn{(\kwd{declare} \OPn{\VAR{decl}})}
370 \OPn{\VAR{form}})}
372 Evaluate \retval{\VAR{form}s} with \VAR{name}s locally defined as
373 symbol-macros.
376 \IT{(\SF*{DEFSETF} \VAR{function} \xorGOO{\VAR{update } \Op{\VAR{documentation}}\\
377 \OPn{\VAR{arg } (\OPn{\VAR{var}})\text{ } \OPn{(\kwd{declare} \OPn{\VAR{
378 decl}})}\text{ } \Op{\VAR{documentation}}}}{\}})}
380 Specify how to \kwd{setf} a place accessed by
381 \retval{\VAR{function}}.
384 \IT{(\SF*{DEFINE-SETF-EXPANDER} \VAR{function} (\OPn{\VAR{macro-arg}})
385 \OPn{(\kwd{declare} \OPn{\VAR{decl}})} \Op{\VAR{documentation}}
386 \OPn{\VAR{form}})}
388 Specify how to \kwd{setf} a place accessed by \retval{\VAR{function}}.
391 \IT{(\FU*{GET-SETF-EXPANSION} \VAR{place} \Op{\VAR{environment}})}
393 Return five values describing how to \kwd{setf} place.
396 \IT{(\SF*{DEFINE-MODIFY-MACRO} \VAR{foo} (\kwd{\&optional}
397 \OPn{\VAR{var}} \kwd{\&rest} \OPn{\VAR{var}}) \VAR{function}
398 \Op{\VAR{documentation}})}
400 Define macro \retval{\VAR{foo}} able to read and write a place.
403 \IT{\CNS*{LAMBDA-LIST-KEYWORDS}}
404 {List of macro lambda list keywords.
407 \end{LIST}
410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 \subsection{Control Flow}
412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
413 \begin{LIST}{1cm}
415 \IT{(\SF*{IF} \VAR{test} \VAR{then} \Op{\VAR{else}\DF{\NIL}})}
416 {Return value of
417 \retval{\VAR{then}} if \VAR{test} returns \T; return value of
418 \retval{\VAR{else}} otherwise.
421 \IT{(\SF*{COND} \OPn{(\VAR{test} \OPn{\VAR{then}}\DF{\VAR{test}})})}
423 Return the \retval{values} of the first
424 \VAR{then}s whose \VAR{test} returns \T; return
425 \retval{\NIL} if each \VAR{test} returns \NIL.
428 \IT{(\xorGOO{\SF*{WHEN}\\
429 \SF*{UNLESS}}{\}} \VAR{test}
430 \OPn{\VAR{foo}}\DF{\NIL})}
432 Evaluate \VAR{foo}s and return \retval{values of last \VAR{foo}} if
433 \VAR{test} returns \T\ or \NIL, respectively. Return \retval{\NIL} otherwise.
436 \IT{(\SF*{CASE} \VAR{test} \OPn{(\VAR{keys} \OPn{\VAR{foo}})}
437 \Op{(\Goo{\T\XOR\kwd*{OTHERWISE}} \OPn{\VAR{bar}})\DF{\NIL}})}
439 Evaluate first \VAR{foo}s one of whose unevaluated \VAR{keys} is
440 \kwd{eql} evaluated \VAR{test} and return \retval{their values}.
441 Return \retval{values of \VAR{bar}s} if no \VAR{keys} match.
444 \IT{(\Goo{\SF*{CCASE}\XOR\SF*{ECASE}} \VAR{test}
445 \OPn{(\VAR{keys} \OPn{\VAR{foo}})})}
447 Evaluate first \VAR{foo}s one of whose unevaluated \VAR{keys} is \kwd{eql} evaluated
448 \VAR{test} and return \retval{their values}. Signal correctible error/non-correctible \kwd{type-error},
449 respectively, if no \VAR{keys} match and return \retval{\NIL} then.
452 \IT{(\SF*{AND} \OPn{\VAR{form}}\DF{\T})}
454 Evaluate \VAR{form}s from left to
455 right. Immediately return \retval{\NIL} if one \VAR{form}'s value is \NIL. Return
456 \retval{values of last \VAR{form}} otherwise.
459 \IT{(\SF*{OR} \OPn{\VAR{form}}\DF{\NIL})}
461 Evaluate \VAR{form}s from left to
462 right. Immediately return \retval{primary value} of first
463 non-\NIL-evaluating form, or \retval{all values} if last \VAR{form}
464 is reached. Return \retval{\NIL} if no \VAR{form} returns \T.
467 \IT{(\kwd*{PROGN} \OPn{\VAR{form}}\DF{\NIL})}
468 {Evaluate \VAR{form}s sequentially. Return
469 \retval{values of last \VAR{form}}.
472 \IT{(\xorGOO{\SF*{PROG}\\
473 \SF*{PROG*}}{\}}
474 (\orGOO{%
475 \VAR{var}\\
476 (\VAR{var } \Op{ \VAR{value}})}{\}^{\!\!*}})
477 \OPn{(\kwd{declare} \OPn{\VAR{decl}})}
478 \xorGOO{\VAR{tag}\\\VAR{form}}{\}^{\!\!*}})}
480 Evaluate \SF{TAGBODY}-like body with \VAR{var}s locally bound (in parallel or sequentially, respectively) to
481 \VAR{value}s. Return \retval{\NIL} or explicitly
482 \retval{\SF{return}ed value}.
485 \IT{\arrGOO{%
486 (\SF*{MULTIPLE-VALUE-PROG1} \VAR{ form-r} \OPn{\VAR{ form}})\\
487 (\SF*{PROG1} \VAR{ form-r} \OPn{\VAR{ form}})\\
488 (\SF*{PROG2} \VAR{ form-a} \VAR{ form-r} \OPn{\VAR{ form}})}{.}}
490 Evaluate forms in order. Return \retval{values/1st value},
491 respectively, of \VAR{form-r}.
494 \IT{(\SF*{PROGV} \VAR{symbols} \VAR{values} \OPn{\VAR{form}})}
496 Evaluate \VAR{form}s with \VAR{symbols} dynamically bound to \VAR{values} or
497 \NIL. Return \retval{values returned by \VAR{form}s}.
500 \IT{(\SF*{DESTRUCTURING-BIND} \VAR{foo} \VAR{bar} \OPn{(\kwd{declare}
501 \OPn{\VAR{decl}})} \OPn{\VAR{form}})}
503 Evaluate \VAR{form}s, and return \retval{values of last \VAR{form}},
504 with variables from tree \VAR{foo} bound to corresponding elements
505 of tree \VAR{bar}.
508 \IT{(\kwd*{MULTIPLE-VALUE-BIND} (\OPn{\VAR{var}}) \VAR{values-form}
509 \OPn{(\kwd{declare} \OPn{\VAR{decl}})} \OPn{\VAR{body-form}})}
510 {Evaluate
511 \VAR{body-form}s with \VAR{var}s bound to the return values of
512 \VAR{values-form}. Return \retval{values returned by \VAR{body-form}s}.
515 \IT{(\xorGOO{\SF*{LET}\\
516 \SF*{LET*}}{\}}(%
517 \orGOO{\VAR{name}\\
518 (\VAR{name }\Op{\VAR{value}})}{\}^{\!\!*}})
519 \OPn{(\kwd{declare} \OPn{\VAR{decl}})}
520 \OPn{\VAR{form}})}
522 Evaluate \VAR{form}s with \VAR{name}s bound (in parallel or
523 sequentially, respectively) to \VAR{value}s or \NIL. Return
524 \retval{values of \VAR{form}s}.
527 \IT{(\SF*{LOCALLY} \OPn{(\kwd{declare} \OPn{\VAR{decl}})}
528 \OPn{\VAR{form}})}
530 Evaluate \VAR{form}s with declarations \VAR{decl} in
531 effect. Return \retval{values of \VAR{form}s}.
534 \IT{(\SF*{RETURN-FROM} \VAR{foo} \Op{\VAR{result}\DF{\NIL}})}
536 Have nearest enclosing \SF{block} \VAR{foo} return with
537 values of \VAR{result}.
540 \IT{(\SF*{RETURN} \Op{\VAR{result}\DF{\NIL}})}
542 Have nearest enclosing block \NIL\ return with values of \VAR{result}.
545 \IT{(\SF*{BLOCK} \VAR{name} \OPn{\VAR{form}})}
546 {Evaluate \VAR{form}s returning
547 \retval{values of last \VAR{form}} unless interrupted by \SF{RETURN-FROM}.
550 \IT{(\SF*{TAGBODY} \Goos{\VAR{tag}\XOR\VAR{form}})}
552 Evaluate \VAR{form}s. \VAR{tag}s (symbols or integers) are targets
553 for \SF{GO}. Return \retval{\NIL}.
556 \IT{(\SF*{GO} \VAR{tag})}
557 {Jump within a \SF{tagbody} to nearest
558 lexically enclosing \kwd{eql} \VAR{tag}.
561 \IT{(\SF*{CATCH} \VAR{tag} \OPn{\VAR{form}})}
562 {Evaluate \VAR{form}s returning
563 \retval{values of last \VAR{form}} unless interrupted by \SF{THROW}.
566 \IT{(\SF*{THROW} \VAR{tag form})}
567 {Have the nearest dynamically
568 enclosing \SF{CATCH} with a tag \FU{eq} \VAR{tag} return with the
569 values of \VAR{form}.
572 \IT{(\FU*{SLEEP} \VAR{n})}
573 {Wait \VAR{n} seconds, return \retval{\NIL}.
576 \end{LIST}
580 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
581 \subsection{Iteration}
582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
584 \begin{LIST}{1cm}
586 \IT{(\xorGOO{\SF*{DO}\\\SF*{DO*}}{\}}
587 (\orGOO{%
588 \VAR{var}\\
589 (\VAR{var } \Op{ \VAR{start } \Op{\VAR{step}}})}{\}^{\!\!*}})
590 (\VAR{stop} \OPn{\VAR{result}})
591 \OPn{(\kwd{declare} \OPn{\VAR{decl}})}
592 \xorGOO{\VAR{tag}\\\VAR{form}}{\}^{\!\!*}})}
594 Evaluate \SF{TAGBODY}-like body with \VAR{var}s successively bound according
595 to the values of the corresponding \VAR{start} and \VAR{step}
596 forms. \VAR{var}s are bound in parallel/sequentially, respectively.
597 Stop iteration when \VAR{stop} is \T. Return \retval{value of
598 last \VAR{result}}.
601 \IT{(\SF*{DOTIMES} (\VAR{var} \VAR{integer} \Op{\VAR{result}})
602 \OPn{(\kwd{declare} \OPn{\VAR{decl}})}
603 \Goos{\VAR{tag}\XOR\VAR{form}})}
605 Evaluate \SF{TAGBODY}-like body with \VAR{var} successively bound
606 to integers from 0 to $\mbox{\VAR{integer}} - 1$. Upon evaluation of
607 \retval{\VAR{result}}, \VAR{var} is \NIL.
610 \IT{(\SF*{DOLIST }(\VAR{var} \VAR{list} \Op{\VAR{result}})
611 \OPn{(\kwd{declare} \OPn{\VAR{decl}})}
612 \Goos{\VAR{tag}\XOR\VAR{form}})}
614 Evaluate \SF{TAGBODY}-like body with \VAR{var} successively bound
615 to the elements of \VAR{list}. Upon evaluation of
616 \retval{\VAR{result}}, \VAR{var} is \NIL.
620 \end{LIST}
622 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 \subsection{Loop Facility}
624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
626 \begin{figure}%
627 \label{loop-overview}%
628 \begin{center}%
629 \begin{sideways}%
631 \arraycolsep0pt
633 \text{\kwd{loop}}
634 \left[
635 \text{\LKWD{named} \VAR{n}}
636 \right]
637 \left\{
638 \begin{array}{l}
639 \text{\LKWD{with} \VAR{var} [\VAR{type}] \LKWD{=} \VAR{foo }}
640 \{\text{\LKWD{and} \VAR{var-n} [\VAR{type}] \LKWD{=} \VAR{bar}\}}^{*} \\
641 \left.\!
642 \begin{array}{l}
643 \text{\LKWD{for}} \\
644 \text{\LKWD{as}}
645 \end{array}\right\}
646 \boxed{
647 \text{\VAR{var} [\VAR{type}]}
648 \left\{
649 \begin{array}{l}
650 \left.\!
651 \begin{array}{l}
652 \left[
653 \left\{
654 \begin{array}{l}
655 \text{\LKWD{upfrom}}\\
656 \text{\LKWD{from}}
657 \end{array}
658 \right\}
659 \text{\VAR{start}\DF{0}}
660 \right]
661 \left[
662 \left\{
663 \begin{array}{l}
664 \text{\LKWD{upto}}\\
665 \text{\LKWD{to}}\\
666 \text{\LKWD{below}}
667 \end{array}
668 \right\}
669 \text{\VAR{form}}
670 \right]\\
671 \text{\LKWD{from} \VAR{start}}
672 \left\{
673 \begin{array}{l}
674 \text{\LKWD{downto}}\\
675 \text{\LKWD{above}}
676 \end{array}
677 \right\}
678 \text{\VAR{form }}\\
679 \text{\LKWD{downfrom} \VAR{start}}
680 \left[
681 \left\{
682 \begin{array}{l}
683 \text{\LKWD{downto}}\\
684 \text{\LKWD{to}}\\
685 \text{\LKWD{above}}
686 \end{array}
687 \right\}
688 \text{\VAR{form}}
689 \right]
690 \end{array}
691 \right\}
692 \left[
693 \text{\LKWD{by} \VAR{step}\DF{1}}
694 \right]\\
695 \left.\!
696 \begin{array}{l}
697 \text{\LKWD{in}} \\
698 \text{\LKWD{on}}
699 \end{array}
700 \right\}
701 \text{\VAR{list}}
702 \left[
703 \text{\LKWD{by} \VAR{form}\DF{\kwd{cdr}}}
704 \right]\\
705 \text{\LKWD{=} \VAR{foo }}
706 \left[
707 \text{\LKWD{then} \VAR{bar}}
708 \right] \\
709 \text{\LKWD{across} \VAR{vector}}\\
710 \text{\LKWD{being}}
711 \left\{
712 \begin{array}{l}
713 \text{\LKWD{the}}\\
714 \text{\LKWD{each}}
715 \end{array}
716 \right\}%
717 \left\{
718 \begin{array}{{l}}
719 \left.\!
720 \begin{array}{l}
721 \left.\!
722 \begin{array}{l}
723 \text{\LKWD{hash-key}}\\
724 \text{\LKWD{hash-keys}}
725 \end{array}
726 \right\}%
727 \left\{
728 \begin{array}{l}
729 \text{\LKWD{of}}\\
730 \text{\LKWD{in}}
731 \end{array}
732 \right\}
733 \text{\VAR{hash }}
734 \left[
735 \text{\LKWD{using} (\LKWD{hash-value} \VAR{v})}
736 \right]\\
737 \left.\!
738 \begin{array}{l}
739 \text{\LKWD{hash-value}}\\
740 \text{\LKWD{hash-values}}
741 \end{array}
742 \right\}%
743 \left\{
744 \begin{array}{l}
745 \text{\LKWD{of}}\\
746 \text{\LKWD{in}}
747 \end{array}
748 \right\}
749 \text{\VAR{hash }}
750 \left[
751 \text{\LKWD{using} (\LKWD{hash-key} \VAR{k})}
752 \right.\\
753 \end{array}
754 \right.\\
755 \left.\!
756 \begin{array}{l}
757 \text{\LKWD{symbol\Op{s}}}\\
758 \text{\LKWD{present-symbol\Op{s}}}\\
759 \text{\LKWD{external-symbol\Op{s}}}
760 \end{array}
761 \right\}%
762 \left[
763 \left\{
764 \begin{array}{l}
765 \text{\LKWD{of}}\\
766 \text{\LKWD{in}}
767 \end{array}
768 \right\} \text{\VAR{package}\DF{\V{*package*}}}
769 \right]
770 \end{array}
771 \right.
772 \end{array}
773 \right\}_{\displaystyle{\mathbb{F}_0}}
774 }%boxed
775 \left\{
776 \text{\LKWD{and} }\boxed{\mathbb{F}_i}
777 \right\}^{\!*}\\
778 \left.\!%
779 \begin{array}{l}
780 \text{\LKWD{initially}} \\
781 \text{\LKWD{finally}}
782 \end{array}
783 \right\}
784 \text{\VAR{form}}^{+} \\
786 \end{array}
787 \right\}^{\!\!\displaystyle{*}}
788 %Bottleneck
789 \left\{
790 \begin{array}{l}
791 \text{\LKWD{repeat} \VAR{num}}\\
792 \left.\!
793 \begin{array}{l}
794 \text{\LKWD{while}}\\
795 \text{\LKWD{until}}\\
796 \text{\LKWD{always}}\\
797 \text{\LKWD{never}}\\
798 \text{\LKWD{thereis}}
799 \end{array}
800 \right\}
801 \text{\VAR{test}}\\
802 \boxed{
803 \left.\!
804 \begin{array}{l}
805 \left.\!
806 \begin{array}{l}
807 \text{\LKWD{do}}\\
808 \text{\LKWD{doing}}
809 \end{array}
810 \right\}
811 \text{\VAR{form}}^{+}\\
812 \text{\LKWD{return}}
813 \left\{
814 \begin{array}{l}
815 \text{\VAR{form}}\\
816 \text{\LKWD{it}}
817 \end{array}
818 \right.\\
819 \left.\!
820 \begin{array}{l}
821 \text{\LKWD{collect\Op{ing}}}\\
822 \text{\LKWD{append\Op{ing}}}\\
823 \text{\LKWD{nconc\Op{ing}}}
824 \end{array}
825 \right\}
826 \left\{
827 \begin{array}{l}
828 \text{\VAR{form}}\\
829 \text{\LKWD{it}}
830 \end{array}
831 \right\} [\text{\LKWD{into }\VAR{var}}]\\
832 \left.\!
833 \begin{array}{l}
834 \text{\LKWD{count\Op{ing}}}\\
835 \text{\LKWD{sum\Op{ming}}}\\
836 \text{\LKWD{maximize}}\\
837 \text{\LKWD{maximizing}}\\
838 \text{\LKWD{minimize}}\\
839 \text{\LKWD{minimizing}}
840 \end{array}
841 \right\}
842 \left\{
843 \begin{array}{l}
844 \text{\VAR{form}}\\
845 \text{\LKWD{it}}
846 \end{array}
847 \right\}
848 [\text{\LKWD{into }\VAR{n}}]
849 [\text{\VAR{type}}]\\
850 \left.\!
851 \begin{array}{l}
852 \text{\LKWD{if}}\\
853 \text{\LKWD{when}}\\
854 \text{\LKWD{unless}}
855 \end{array}
856 \right\}%
857 \text{\VAR{test }}
858 \boxed{\mathbb{S}_i}\{\text{\LKWD{and}}%
859 \boxed{\mathbb{S}_j}\}^{*}[\text{\LKWD{else}}%
860 \boxed{\mathbb{S}_k}\{\text{\LKWD{and}}%
861 \boxed{\mathbb{S}_l}\}^{*}][\text{\LKWD{end}}]
862 \end{array}
863 \right._{\!\!\!\!\displaystyle{\mathbb{S}_0}}
864 }%boxed
866 \left.\!
867 \begin{array}{l}
868 \text{\LKWD{initially}} \\
869 \text{\LKWD{finally}}
870 \end{array}
871 \right\}
872 \text{\VAR{form}}^{+}
873 \end{array}
874 \right\}^{\displaystyle{\!\!*}}
876 \!)%
877 \end{sideways}%
878 \end{center}\vspace{-1em}
879 \caption{Loop Facility, Overview.}%
880 \end{figure}
883 \begin{LIST}{1cm}
885 \IT{(\SF*{LOOP} \OPn{\VAR{form}})}
887 Simple Loop. If \VAR{form}s do
888 not include any keywords of the Loop Facility, evaluate them forever.
891 \IT{(\SF*{LOOP} \OPn{\VAR{form}})}
893 Loop Facility. If there are loop facility keywords in \VAR{form}s
894 see below and p.\ \pageref{loop-overview}.
897 \begin{LIST}{.5cm}
899 \IT{\LKWD*{named} \VAR{n}}
901 Give implicit \kwd{block} of loop a name.
904 \IT{\LKWD*{with} \VAR{var} \Op{\VAR{type}} \LKWD*{=} \VAR{foo} \Goos{\LKWD*{and}
905 \VAR{var-n} \Op{\VAR{type}} \LKWD*{=} \VAR{bar}}}
907 Initialize local variables in parallel.
910 \IT{\Goo{\LKWD*{initially}\XOR\LKWD*{finally}} \RP{\VAR{form}}}
912 Evaluate \VAR{form}s before begin, or after end, respectively, of iterations.
915 \IT{\Goo{\LKWD*{for}\XOR\LKWD*{as}} \VAR{var} \Op{\VAR{type}}}
917 Begin of iteration control clause.
920 \begin{LIST}{.5cm}
922 \IT{\Goo{\LKWD*{upfrom}\XOR\LKWD*{from}\XOR\LKWD*{downfrom}}
923 \VAR{start}}
925 Start stepping with \VAR{start}
928 \IT{\Goo{\LKWD*{upto}\XOR\LKWD*{downto}\XOR\LKWD*{to}\XOR\LKWD*{below}\XOR\LKWD*{above}}
929 \VAR{form}}
931 Specify \VAR{form} as the end value for stepping.
934 \IT{\Goo{\LKWD*{in}\XOR\LKWD*{on}} \VAR{list}}
936 Bind \VAR{var} to successive elements/tails, respectively, of \VAR{list}.
939 \IT{\LKWD*{by} \Goo{\VAR{step}\DF{1}\XOR\VAR{function}\DF{\FU{cdr}}}}
941 Specify the (positive) decrement or increment or the
942 \VAR{function} to apply to the list.
945 \IT{\LKWD*{=} \VAR{foo} \Op{\LKWD*{then}
946 \VAR{bar}\DF{\VAR{foo}}}}
948 Bind \VAR{var} in the first iteration to \VAR{foo} and later to \VAR{bar}.
951 \IT{\LKWD*{across} \VAR{vector}}
953 Bind \VAR{var} to successive elements of \VAR{vector}.
956 \IT{\LKWD*{being} \Goo{\LKWD*{the}\XOR\LKWD*{each}}}
958 Iterate over a hash table or a package.
961 \begin{LIST}{.5cm}
963 \IT{\Goo{\LKWD*{hash-key}\XOR\LKWD*{hash-keys}} \Goo{\LKWD*{of}\XOR\LKWD*{in}} \VAR{hash-table}
964 \Op{\LKWD*{using} (\LKWD*{hash-value} \VAR{value})}}
966 Bind \VAR{var} successively to the keys of \VAR{hash-table}; bind \VAR{value} to corresponding values.
969 \IT{\Goo{\LKWD*{hash-value}\XOR\LKWD*{hash-values}} \Goo{\LKWD*{of}\XOR\LKWD*{in}} \VAR{hash-table}
970 \Op{\LKWD*{using} (\LKWD*{hash-key} \VAR{key})}}
972 Bind \VAR{var} successively to the values of \VAR{hash-table}; bind \VAR{key} to corresponding keys.
975 \IT{\Goo{\LKWD*{symbol}\XOR\LKWD*{symbols}\XOR\LKWD*{present-symbol}\XOR\LKWD*{present-symbols}\XOR\LKWD*{external-symbol}\XOR\LKWD*{external-symbols}}
976 \Op{\Goo{\LKWD*{of}\XOR\LKWD*{in}}
977 \VAR{package}\DF{\V{*package*}}}}
979 Bind \VAR{var} successively to the symbols, or the present symbols, or the external symbols, respectively, of \VAR{package}.
982 \end{LIST}
983 \end{LIST}
985 \IT{\LKWD*{and} \VAR{var} \Op{\VAR{type}}}
987 Begin of another iteration control clause with variables initialized and stepped in parallel.
990 \IT{\Goo{\LKWD*{do}\XOR\LKWD*{doing}} \RP{\VAR{form}}}
992 Evaluate \VAR{form}s in every iteration.
995 \IT{\LKWD*{it}}
997 Value of the test form of an enclosing \LKWD{if}, \LKWD{when},
998 or \LKWD{unless} clause.
1001 \IT{\LKWD*{return} \Goo{\VAR{form}\XOR\LKWD*{it}}}
1003 Return immediately with value of \VAR{form} or \LKWD{it}.
1006 \IT{\Goo{\LKWD*{collect}\XOR\LKWD*{collecting}}
1007 \Goo{\VAR{form}\XOR\LKWD*{it}} \Op{\LKWD*{into} \VAR{list}}}
1009 Collect values of \VAR{form} or \LKWD{it} into \VAR{list}. If no \VAR{list} is given, collect into an anonymous list
1010 which is returned after termination.
1013 \IT{\Goo{\LKWD*{append}\XOR\LKWD*{appending}\XOR\LKWD*{nconc}\XOR\LKWD*{nconcing}}
1014 \Goo{\VAR{form}\XOR\LKWD*{it}} \Op{\LKWD*{into}
1015 \VAR{list}}}
1017 Concatenate values of \VAR{form} or \LKWD{it}, which should be lists, into \VAR{list} by the means of \FU{append}
1018 or \FU{nconc}, respectively. If no \VAR{list} is given, collect into an anonymous list
1019 which is returned after termination.
1022 \IT{\Goo{\LKWD*{count}\XOR\LKWD*{counting}}
1023 \Goo{\VAR{form}\XOR\LKWD*{it}} \Op{\LKWD*{into}
1024 \VAR{n}} \Op{\VAR{type}}}
1026 Count the number of times the value of \VAR{form} or of \LKWD{it} is \T.
1027 If no \VAR{n} is given, count into an anonymous variable
1028 which is returned after termination.
1031 \IT{\Goo{\LKWD*{sum}\XOR\LKWD*{summing}}
1032 \Goo{\VAR{form}\XOR\LKWD*{it}} \Op{\LKWD*{into}
1033 \VAR{sum}} \Op{\VAR{type}}}
1035 Calculate the sum of the values of \VAR{form} or of \LKWD{it}.
1036 If no \VAR{sum} is given, sum into an anonymous variable
1037 which is returned after termination.
1040 \IT{\Goo{\LKWD*{maximize}\XOR\LKWD*{maximizing}\XOR
1041 \LKWD*{minimize}\XOR
1042 \LKWD*{minimizing}} \Goo{\VAR{form}\XOR\LKWD*{it}} \Op{\LKWD*{into}
1043 \VAR{max-min}} \Op{\VAR{type}}}
1045 Determine the maximum or minimum, respectively, of the values of
1046 \VAR{form} or of \LKWD{it}.
1047 If no \VAR{max-min} is given, use an anonymous variable
1048 which is returned after termination.
1051 \IT{\Goo{\LKWD*{if}\XOR\LKWD*{when}\XOR\LKWD*{unless}} \VAR{ test}
1052 \VAR{form-i} \Goos{\LKWD*{and}
1053 \VAR{form-j}} \Op{\LKWD*{else} \VAR{form-k} \Goos{\LKWD*{and}
1054 \VAR{form-l}}} \Op{\LKWD*{end}}}
1056 If \VAR{test} returns \T, \T, or \NIL, respectively, evaluate
1057 \VAR{form-i} and \VAR{form-j}s; otherwise, evaluate \VAR{form-k}
1058 and \VAR{form-l}s. Inside \VAR{form-i} and \VAR{form-k}, the value
1059 of \VAR{test} is accessible by \LKWD*{it}.
1062 \IT{\LKWD*{repeat} \VAR{num}}
1064 Terminate \SF{loop} after \VAR{num} times; \VAR{num} is evaluated once.
1067 \IT{\Goo{\LKWD*{while}\XOR\LKWD*{until}} \VAR{test}}
1069 Continue iteration until \VAR{test} returns \NIL, or \T, respectively.
1072 \IT{\Goo{\LKWD*{always}\XOR\LKWD{never}} \VAR{test}}
1074 Terminate \SF{loop} returning \NIL\ and skipping any
1075 \LKWD*{finally} parts as soon as \VAR{test} is \NIL, or \T,
1076 respectively. Otherwise continue \SF{loop} with its default return
1077 value set to \T.
1080 \IT{\LKWD*{thereis} \VAR{test}}
1082 Terminate \SF{loop} when \VAR{test} is \T\ and return value of
1083 \VAR{test}, skipping any \LKWD*{finally} parts. Otherwise continue
1084 \SF{loop} with its default return value set to \NIL.
1087 \IT{\LKWD*{loop-finish}}
1089 Terminate \SF{loop} immediately; skip any \LKWD*{finally} parts.
1091 \end{LIST}
1092 \end{LIST}