changed define-symbol-macro entry
[clqr.git] / clqr-control-structure.tex
blobc0daffc075ba61d365864f400e51d2baecd39bf6
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{(\MC*{DEFVAR} \NEV{\VAR{name}} \OP{\VAR{form}
80 \Op{\NEV{\VAR{doc}}}})}
82 Unless bound already, assign value of \VAR{form} to dynamic variable
83 \retval{\VAR{name}}.
86 \IT{(\MC*{DEFPARAMETER} \NEV{\VAR{name}} \VAR{form}
87 \Op{\NEV{\VAR{doc}}})}
89 Assign value of \VAR{form} to dynamic variable \retval{\VAR{name}}.
92 \IT{(\MC*{DEFCONSTANT} \NEV{\VAR{name}} \VAR{form}
93 \Op{\NEV{\VAR{doc}}})}
95 Assign value of \VAR{form} to global constant \retval{\VAR{name}}.
98 \IT{(\xorGOO{\MC*{SETF}\\
99 \MC*{PSETF}}{\}} \Goos{\VAR{place}
100 \VAR{form}})}
102 Set \VAR{place}s to values of \VAR{form}s. Return \retval{value
103 of last \VAR{form}}. Work sequentially/in parallel, respectively.
106 \IT{(\xorGOO{\SO*{SETQ}\\
107 \MC*{PSETQ}}{\}} \Goos{\VAR{symbol}
108 \VAR{form}})}
110 Set \VAR{symbol}s to values of \VAR{form}s. Return \retval{value
111 of last \VAR{form}}. Work sequentially/in parallel, respectively.
114 \IT{(\FU*{SET} \DES{\VAR{symbol}} \VAR{foo})}
116 Set \VAR{symbol}'s value cell to \retval{\VAR{foo}}.
119 \IT{(\MC*{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{(\MC*{SHIFTF} \RP{\DES{\VAR{place}}} \VAR{foo})}
127 Store value of \VAR{foo} in rightmost \VAR{place} shifting values of
128 \VAR{place}s left, returning \retval{first \VAR{place}}.
131 \IT{(\MC*{ROTATEF} \OPn{\DES{\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} \DES{\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 } \DES{\VAR{symbol}} \VAR{ key})\\
163 (\MC*{REMF } \DES{\VAR{place}} \VAR{ key})}{.}}
165 Remove first 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}
178 \begin{flushleft}
179 Below, ordinary lambda list (\OPn{\VAR{ord-$\lambda$}}) has the form\\
180 (\OPn{\VAR{var}}
181 \OP{\kwd*{\&optional} \xorGOO{%
182 \VAR{var}\\
183 (\VAR{var } \OP{\VAR{init } \Op{\VAR{supplied-p}}})}{\}}}
184 \penalty-5
185 \Op{\kwd*{\&rest} \VAR{var}}
186 \penalty-5
187 \OP{\kwd*{\&key} \xorGOO{%
188 \VAR{var}\\
189 (\xorGOO{%
190 \VAR{var}\\
191 (\kwd{:}\VAR{key } \VAR{var})}{\}}
192 \text{ }\OP{\VAR{init }\Op{\VAR{supplied-p}}})}{\}^{\!\!*}}
193 \penalty-5
194 \Op{\kwd*{\&allow-other-keys}}}
195 \penalty-5
196 \OP{\kwd*{\&aux} \xorGOO{%
197 \VAR{var}\\
198 (\VAR{var } \Op{\VAR{init}})}{\}}}).\\
199 \VAR{supplied-p} is \T\ if there is a corresponding argument.
200 \end{flushleft}
202 \begin{LIST}{1cm}
204 \IT{(\xorGOO{\MC*{DEFUN} \VAR{ foo}\\ \MC*{LAMBDA}}{\}}
205 (\VAR{\OPn{ord-$\lambda$}}) \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
206 \Op{\NEV{\VAR{doc}}}
207 \OPn{\VAR{form}})}
209 Define function with \retval{name \VAR{foo}} or an anonymous
210 function, respectively, which
211 applies \VAR{form}s to \VAR{ord-$\lambda$}s.
214 \IT{(\xorGOO{\SO*{FLET}\\
215 \SO*{LABELS}}{\}}
216 (\OPn{(\VAR{foo}
217 (\OPn{\VAR{ord-$\lambda$}})
218 \OPn{(\kwd{declare} \OPn{\NEV{\VAR{local-decl}}})}%
219 \Op{\NEV{\VAR{doc}}}
220 \OPn{\VAR{local-form}})}) \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
221 \OPn{\VAR{form}})}
223 Evaluate \VAR{form}s with
224 locally defined functions \VAR{foo}. Only for \SO{LABELS},
225 \VAR{foo}s are visible inside \VAR{local-forms}. Return
226 \retval{values of \VAR{form}s}.
229 \IT{(\SO*{FUNCTION} \VAR{foo})}
230 {Return \retval{function named \VAR{foo}}.
233 \IT{(\FU*{APPLY} \VAR{function} \RP{\VAR{arg}})}
235 Return \retval{value of \VAR{function}} called on
236 \VAR{arg}s. Last \VAR{arg} must be a list.
239 \IT{(\FU*{FUNCALL} \VAR{function} \OPn{arg})}
241 Return \retval{value of \VAR{function}} called with \VAR{arg}s.
244 \IT{(\SO*{MULTIPLE-VALUE-CALL} \VAR{foo} \OPn{\VAR{form}})}
245 {Call function
246 \VAR{foo} with all the values of \VAR{form}s as its arguments. Return
247 \retval{values returned by \VAR{foo}}.
250 \IT{(\FU*{VALUES-LIST} \VAR{list})}
252 Return \retval{elements of \VAR{list}}.
255 \IT{(\FU*{VALUES} \OPn{\VAR{foo}})}
257 Return \retval{\VAR{foo}s} as multiple values. \kwd{setf}able.
260 \IT{(\FU*{MULTIPLE-VALUE-LIST} \VAR{form})}
262 Return in a \retval{list} values of \VAR{form}.
265 \IT{(\FU*{NTH-VALUE} \VAR{n} \VAR{form})}
267 Zero-indexed \retval{\VAR{n}th return value} of \VAR{form}.
270 \IT{(\FU*{COMPLEMENT} \VAR{function})}
272 Return \retval{new function} with same arguments and same side effects
273 as \VAR{function}, but with complementary truth value.
276 \IT{(\FU*{CONSTANTLY} \VAR{foo})}
278 Return \retval{function} of any number of arguments returning \VAR{foo}.
281 \IT{(\FU*{IDENTITY} \VAR{foo})}
283 Return \retval{\VAR{foo}}.
286 \IT{(\FU*{FUNCTION-LAMBDA-EXPRESSION} \VAR{function})}
288 If available, return \retval{lambda expression} of \VAR{function},
289 \retvalii{\NIL} if \VAR{function} was defined in an environment
290 without bindings, and \retvaliii{name} of \VAR{function}.
293 \IT{(\FU*{FDEFINITION} \VAR{foo})}
295 \retval{Definition} of function \VAR{foo}. \kwd{setf}able.
298 \IT{(\FU*{FMAKUNBOUND} \VAR{foo})}
300 Remove global function or macro definition \retval{\VAR{foo}}.
303 \IT{\arrGOO{\CNS*{CALL-ARGUMENTS-LIMIT}\\
304 \CNS*{LAMBDA-PARAMETERS-LIMIT}}{.}}
306 Upper bound of the number of function arguments or lambda list
307 parameters, respectively; $\geq50$.
310 \IT{\CNS*{MULTIPLE-VALUES-LIMIT}}
312 Upper bound of the number of values a function can return; $\geq20$.
315 \end{LIST}
318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
319 \subsection{Macros}
320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322 \begin{flushleft}
323 Below, macro lambda list (\OPn{\VAR{macro-$\lambda$}}) has the form of
324 either
325 \penalty-5
326 (\Op{\kwd*{\&whole}
327 \xorGOO{%
328 \VAR{var}\\
329 (\OPn{\VAR{macro-$\lambda$}})}{\}}}
330 \penalty-5
331 \Op{\VAR{\&Ev}}
332 \penalty-5
333 \xorGOO{%
334 \VAR{var}\\
335 (\OPn{\VAR{macro-$\lambda$}})}{\}^{\!\!*}}
336 \penalty-5
337 \Op{\VAR{\&Ev}}
338 \penalty-5
339 \Op{\kwd*{\&optional}
340 \xorGOO{%
341 \VAR{var}\\
342 (\VAR{var } \OP{\VAR{init } \Op{\VAR{supplied-p}}})}{\}^{\!\!*}}}
343 \penalty-5
344 \Op{\VAR{\&Ev}}
345 \penalty-5
346 \Op{%
347 \xorGOO{%
348 \kwd*{\&rest}\\
349 \kwd*{\&body}}{\}}
350 \xorGOO{%
351 \VAR{var}\\
352 (\OPn{\VAR{macro-$\lambda$}})}{\}}}
353 \penalty-5
354 \Op{\VAR{\&Ev}}
355 \penalty-5
356 \OP{\kwd*{\&key}
357 \xorGOO{%
358 \VAR{var}\\
359 (\xorGOO{%
360 \VAR{var}\\
361 (\kwd{:}\VAR{key } \VAR{var})}{\}}
362 \text{ }\OP{\VAR{init } \Op{\VAR{supplied-p}}})}{\}^{\!\!*}}
363 \Op{\VAR{\&Ev}}
364 \Op{\kwd*{\&allow-other-keys}}}
365 \penalty-5
366 \Op{\kwd*{\&aux}
367 \xorGOO{%
368 \VAR{var}\\
369 (\VAR{var } \Op{\VAR{init}})}{\}^{\!\!*}}}
370 \penalty-5
371 \Op{\VAR{\&Ev}})
374 \penalty-5
375 (\Op{\kwd*{\&whole}
376 \xorGOO{%
377 \VAR{var}\\
378 (\OPn{\VAR{macro-$\lambda$}})}{\}}}
379 \penalty-5
380 \Op{\VAR{\&Ev}}
381 \penalty-5
382 \xorGOO{%
383 \VAR{var}\\
384 (\OPn{\VAR{macro-$\lambda$}})}{\}^{\!\!*}}
385 \penalty-5
386 \Op{\VAR{\&Ev}}
387 \penalty-5
388 \Op{\kwd*{\&optional}
389 \xorGOO{%
390 \VAR{var}\\
391 (\VAR{var } \OP{\VAR{init } \Op{\VAR{supplied-p}}})}{\}^{\!\!*}}}
392 \penalty-5
393 \Op{\VAR{\&Ev}}
394 \kwd{.}
395 \xorGOO{%
396 \VAR{var}\\
397 (\OPn{\VAR{macro-$\lambda$}})}{\}}).
398 \penalty-5
399 One toplevel \Op{\VAR{\&Ev}} may be replaced by \kwd*{\&environment}
400 \VAR{var}. \VAR{supplied-p} is \T\ if there is a corresponding
401 argument.
402 \end{flushleft}
404 \begin{LIST}{1cm}
406 \IT{(\xorGOO{\MC*{DEFMACRO}\\
407 \FU*{DEFINE-COMPILER-MACRO}}{\}}
408 \VAR{foo} (\OPn{\VAR{macro-$\lambda$}})
409 \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})} \Op{\NEV{\VAR{doc}}}
410 \OPn{\VAR{form}})}
412 Define macro \retval{\VAR{foo}} which on evaluation as (\VAR{foo}
413 \VAR{tree}) applies expanded \VAR{form}s to arguments from
414 \VAR{tree} which corresponds to \VAR{tree}-shaped
415 \VAR{macro-$\lambda$}s.
418 \IT{(\MC*{DEFINE-SYMBOL-MACRO} \VAR{foo} \VAR{form})}
420 Define symbol macro \retval{\VAR{foo}} which on evaluation evaluates
421 expanded \VAR{form}.
424 \IT{(\SO*{MACROLET} (\OPn{(\VAR{name} (\OPn{\VAR{macro-$\lambda$}})
425 \OPn{(\kwd{declare} \OPn{\NEV{\VAR{local-decl}}})}
426 \Op{\NEV{\VAR{doc}}} \OPn{\VAR{macro-form}})}) \OPn{(\kwd{declare}
427 \OPn{\NEV{\VAR{decl}}})} \OPn{\VAR{form}})}
429 Evaluate \retval{\VAR{form}s} with \VAR{name}s locally defined
430 as macros which are invisible to each other.
433 \IT{(\SO*{SYMBOL-MACROLET} (\OPn{(\VAR{name}
434 \VAR{expansion-form})}) \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
435 \OPn{\VAR{form}})}
437 Evaluate \retval{\VAR{form}s} with \VAR{name}s locally defined as
438 symbol-macros.
441 \IT{(\MC*{DEFSETF} \NEV{\VAR{function}} \xorGOO{%
442 \NEV{\VAR{update}} \text{ } \Op{\NEV{\VAR{doc}}}\\
443 (\OPn{\VAR{setf-$\lambda$}}) \text{ } (\OPn{\VAR{var}}) \text{ }
444 \OPn{(\kwd{declare } \OPn{\NEV{\VAR{decl}}})}\text{ }
445 \Op{\NEV{\VAR{doc}}} \text{ } \OPn{form}}{\}})
446 \penalty-5
447 where setf lambda list (\OPn{\VAR{setf-$\lambda$}}) has the form
448 \penalty-5
449 (\OPn{\VAR{var}}
450 \OP{\kwd*{\&optional} \xorGOO{%
451 \VAR{var}\\
452 (\VAR{var } \OP{\VAR{init } \Op{\VAR{supplied-p}}})}{\}}}
453 \penalty-5
454 \Op{\kwd*{\&rest} \VAR{var}}
455 \penalty-5
456 \OP{\kwd*{\&key} \xorGOO{%
457 \VAR{var}\\
458 (\xorGOO{%
459 \VAR{var}\\
460 (\kwd{:}\VAR{key } \VAR{var})}{\}}
461 \text{ }\OP{\VAR{init }\Op{\VAR{supplied-p}}})}{\}^{\!\!*}}
462 \penalty-5
463 \Op{\kwd*{\&allow-other-keys}}}
464 \penalty-5
465 \OP{\kwd*{\&environment} \VAR{var}}%
469 Specify how to \kwd{setf} a place accessed by
470 \retval{\VAR{function}}. %FIXME:AUGMENT
473 \IT{(\MC*{DEFINE-SETF-EXPANDER} \VAR{function} (\OPn{\VAR{macro-$\lambda$}})
474 \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})} \Op{\NEV{\VAR{doc}}}
475 \OPn{\VAR{form}})}
477 Specify how to \kwd{setf} a place accessed by \retval{\VAR{function}}.
480 \IT{(\FU*{GET-SETF-EXPANSION} \VAR{place} \Op{\VAR{environment}})}
482 Return five values describing how to \kwd{setf} place.
485 \IT{(\MC*{DEFINE-MODIFY-MACRO} \VAR{foo} (\kwd{\&optional}
486 \OPn{\VAR{var}} \kwd{\&rest} \OPn{\VAR{var}}) \VAR{function}
487 \Op{\NEV{\VAR{doc}}})}
489 Define macro \retval{\VAR{foo}} able to read and write a place.
492 \IT{\CNS*{LAMBDA-LIST-KEYWORDS}}
493 {List of macro lambda list keywords.
496 \end{LIST}
499 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
500 \subsection{Control Flow}
501 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
502 \begin{LIST}{1cm}
504 \IT{(\SO*{IF} \VAR{test} \VAR{then} \Op{\VAR{else}\DF{\NIL}})}
505 {Return value of
506 \retval{\VAR{then}} if \VAR{test} returns \T; return value of
507 \retval{\VAR{else}} otherwise.
510 \IT{(\MC*{COND} \OPn{(\VAR{test} \OPn{\VAR{then}}\DF{\VAR{test}})})}
512 Return the \retval{values} of the first
513 \VAR{then} whose \VAR{test} returns \T; return
514 \retval{\NIL} if each \VAR{test} returns \NIL.
517 \IT{(\xorGOO{\MC*{WHEN}\\
518 \MC*{UNLESS}}{\}} \VAR{test}
519 \OPn{\VAR{foo}}\DF{\NIL})}
521 Evaluate \VAR{foo}s and return \retval{values of last \VAR{foo}} if
522 \VAR{test} returns \T\ or \NIL, respectively. Return \retval{\NIL} otherwise.
525 \IT{(\MC*{CASE} \VAR{test} \OPn{(\VAR{keys} \OPn{\VAR{foo}})}
526 \Op{(\Goo{\T\XOR\kwd*{OTHERWISE}} \OPn{\VAR{bar}})\DF{\NIL}})}
528 Evaluate first \VAR{foo}s one of whose unevaluated \VAR{keys} is
529 \kwd{eql} evaluated \VAR{test} and return \retval{their values}.
530 Return \retval{values of \VAR{bar}s} if no \VAR{keys} match.
533 \IT{(\Goo{\MC*{CCASE}\XOR\MC*{ECASE}} \VAR{test}
534 \OPn{(\VAR{keys} \OPn{\VAR{foo}})})}
536 Evaluate first \VAR{foo}s one of whose unevaluated \VAR{keys} is \kwd{eql} evaluated
537 \VAR{test} and return \retval{their values}. Signal correctable error/non-correctable \kwd{type-error},
538 respectively, if no \VAR{keys} match and return \retval{\NIL} then.
541 \IT{(\MC*{AND} \OPn{\VAR{form}}\DF{\T})}
543 Evaluate \VAR{form}s from left to
544 right. Immediately return \retval{\NIL} if one \VAR{form}'s value is \NIL. Return
545 \retval{values of last \VAR{form}} otherwise.
548 \IT{(\MC*{OR} \OPn{\VAR{form}}\DF{\NIL})}
550 Evaluate \VAR{form}s from left to
551 right. Immediately return \retval{primary value} of first
552 non-\NIL-evaluating form, or \retval{all values} if last \VAR{form}
553 is reached. Return \retval{\NIL} if no \VAR{form} returns \T.
556 \IT{(\SO*{PROGN} \OPn{\VAR{form}}\DF{\NIL})}
557 {Evaluate \VAR{form}s sequentially. Return
558 \retval{values of last \VAR{form}}.
561 \IT{(\xorGOO{\MC*{PROG}\\
562 \MC*{PROG*}}{\}}
563 (\orGOO{%
564 \VAR{var}\\
565 (\VAR{var } \Op{ \VAR{value}})}{\}^{\!\!*}})
566 \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
567 \xorGOO{\NEV{\VAR{tag}}\\\VAR{form}}{\}^{\!\!*}})}
569 Evaluate \SO{TAGBODY}-like body with \VAR{var}s locally bound (in parallel or sequentially, respectively) to
570 \VAR{value}s. Return \retval{\NIL} or explicitly
571 \retval{\MC{return}ed value}.
574 \IT{\arrGOO{%
575 (\SO*{MULTIPLE-VALUE-PROG1} \VAR{ form-r} \OPn{\VAR{ form}})\\
576 (\MC*{PROG1} \VAR{ form-r} \OPn{\VAR{ form}})\\
577 (\MC*{PROG2} \VAR{ form-a} \VAR{ form-r} \OPn{\VAR{ form}})}{.}}
579 Evaluate forms in order. Return \retval{values/1st value},
580 respectively, of \VAR{form-r}.
583 \IT{(\SO*{PROGV} \VAR{symbols} \VAR{values} \OPn{\VAR{form}})}
585 Evaluate \VAR{form}s with \VAR{symbols} dynamically bound to \VAR{values} or
586 \NIL. Return \retval{values returned by \VAR{form}s}.
589 \IT{(\MC*{DESTRUCTURING-BIND} \VAR{foo} \VAR{bar} \OPn{(\kwd{declare}
590 \OPn{\NEV{\VAR{decl}}})} \OPn{\VAR{form}})}
592 Evaluate \VAR{form}s, and return \retval{values of last \VAR{form}},
593 with variables from tree \VAR{foo} bound to corresponding elements
594 of tree \VAR{bar}.
597 \IT{(\MC*{MULTIPLE-VALUE-BIND} (\OPn{\VAR{var}}) \VAR{values-form}
598 \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})} \OPn{\VAR{body-form}})}
599 {Evaluate
600 \VAR{body-form}s with \VAR{var}s bound to the return values of
601 \VAR{values-form}. Return \retval{values of \VAR{body-form}s}.
604 \IT{(\xorGOO{\SO*{LET}\\
605 \SO*{LET*}}{\}}(%
606 \orGOO{\VAR{name}\\
607 (\VAR{name }\Op{\VAR{value}})}{\}^{\!\!*}})
608 \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
609 \OPn{\VAR{form}})}
611 Evaluate \VAR{form}s with \VAR{name}s bound (in parallel or
612 sequentially, respectively) to \VAR{value}s or \NIL. Return
613 \retval{values of \VAR{form}s}.
616 \IT{(\SO*{LOCALLY} \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
617 \OPn{\VAR{form}})}
619 Evaluate \VAR{form}s with declarations \VAR{decl} in
620 effect. Return \retval{values of \VAR{form}s}.
623 \IT{(\SO*{RETURN-FROM} \VAR{foo} \Op{\VAR{result}\DF{\NIL}})}
625 Have nearest enclosing \SO{block} \VAR{foo} return with
626 values of \VAR{result}.
629 \IT{(\MC*{RETURN} \Op{\VAR{result}\DF{\NIL}})}
631 Have nearest enclosing block \NIL\ return with values of \VAR{result}.
634 \IT{(\SO*{BLOCK} \VAR{name} \OPn{\VAR{form}})}
635 {Evaluate \VAR{form}s returning
636 \retval{values of last \VAR{form}} unless interrupted by \SO{RETURN-FROM}.
639 \IT{(\SO*{TAGBODY} \Goos{\NEV{\VAR{tag}}\XOR\VAR{form}})}
641 Evaluate \VAR{form}s. \VAR{tag}s (symbols or integers) are targets
642 for \SO{GO}. Return \retval{\NIL}.
645 \IT{(\SO*{GO} \VAR{tag})}
646 {Jump within a \SO{tagbody} to nearest
647 lexically enclosing \kwd{eql} \VAR{tag}.
650 \IT{(\SO*{CATCH} \VAR{tag} \OPn{\VAR{form}})}
651 {Evaluate \VAR{form}s returning
652 \retval{values of last \VAR{form}} unless interrupted by \SO{THROW}.
655 \IT{(\SO*{THROW} \VAR{tag} \VAR{form})}
656 {Have the nearest dynamically
657 enclosing \SO{CATCH} with a tag \FU{eq} \VAR{tag} return with the
658 values of \VAR{form}.
661 \IT{(\FU*{SLEEP} \VAR{n})}
662 {Wait \VAR{n} seconds, return \retval{\NIL}.
665 \end{LIST}
669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670 \subsection{Iteration}
671 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
673 \begin{LIST}{1cm}
675 \IT{(\xorGOO{\MC*{DO}\\
676 \MC*{DO*}}{\}}
677 (\orGOO{%
678 \VAR{var}\\
679 (\VAR{var } \OP{ \VAR{start } \Op{\VAR{step}}})}{\}^{\!\!*}})
680 (\VAR{stop} \OPn{\VAR{result}})
681 \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
682 \xorGOO{\NEV{\VAR{tag}}\\\VAR{form}}{\}^{\!\!*}})}
684 Evaluate \SO{TAGBODY}-like body with \VAR{var}s successively bound according
685 to the values of the corresponding \VAR{start} and \VAR{step}
686 forms. \VAR{var}s are bound in parallel/sequentially, respectively.
687 Stop iteration when \VAR{stop} is \T. Return \retval{value of
688 last \VAR{result}}.
691 \IT{(\MC*{DOTIMES} (\VAR{var} \VAR{integer} \Op{\VAR{result}})
692 \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
693 \Goos{\NEV{\VAR{tag}}\XOR\VAR{form}})}
695 Evaluate \SO{TAGBODY}-like body with \VAR{var} successively bound
696 to integers from 0 to $\mbox{\VAR{integer}} - 1$. Upon evaluation of
697 \retval{\VAR{result}}, \VAR{var} is \NIL.
700 \IT{(\MC*{DOLIST }(\VAR{var} \VAR{list} \Op{\VAR{result}})
701 \OPn{(\kwd{declare} \OPn{\NEV{\VAR{decl}}})}
702 \Goos{\NEV{\VAR{tag}}\XOR\VAR{form}})}
704 Evaluate \SO{TAGBODY}-like body with \VAR{var} successively bound
705 to the elements of \VAR{list}. Upon evaluation of
706 \retval{\VAR{result}}, \VAR{var} is \NIL.
710 \end{LIST}
712 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
713 \subsection{Loop Facility}
714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
716 \begin{figure}%
717 \label{loop-overview}%
718 \begin{center}%
719 \begin{sideways}%
721 \arraycolsep0pt
723 \text{\kwd{loop}}
724 \left[
725 \text{\LKWD{named} \VAR{n}}
726 \right]
727 \left\{
728 \begin{array}{l}
729 \text{\LKWD{with} \VAR{var} [\VAR{type}] \LKWD{=} \VAR{foo }}
730 \{\text{\LKWD{and} \VAR{var-n} [\VAR{type}] \LKWD{=} \VAR{bar}\}}^{*} \\
731 \left.\!
732 \begin{array}{l}
733 \text{\LKWD{for}} \\
734 \text{\LKWD{as}}
735 \end{array}\right\}
736 \boxed{
737 \text{\VAR{var} [\VAR{type}]}
738 \left\{
739 \begin{array}{l}
740 \left.\!
741 \begin{array}{l}
742 \left[
743 \left\{
744 \begin{array}{l}
745 \text{\LKWD{upfrom}}\\
746 \text{\LKWD{from}}
747 \end{array}
748 \right\}
749 \text{\VAR{start}\DF{\LIT{0}}}
750 \right]
751 \left[
752 \left\{
753 \begin{array}{l}
754 \text{\LKWD{upto}}\\
755 \text{\LKWD{to}}\\
756 \text{\LKWD{below}}
757 \end{array}
758 \right\}
759 \text{\VAR{form}}
760 \right]\\
761 \text{\LKWD{from} \VAR{start}}
762 \left\{
763 \begin{array}{l}
764 \text{\LKWD{downto}}\\
765 \text{\LKWD{above}}
766 \end{array}
767 \right\}
768 \text{\VAR{form }}\\
769 \text{\LKWD{downfrom} \VAR{start}}
770 \left[
771 \left\{
772 \begin{array}{l}
773 \text{\LKWD{downto}}\\
774 \text{\LKWD{to}}\\
775 \text{\LKWD{above}}
776 \end{array}
777 \right\}
778 \text{\VAR{form}}
779 \right]
780 \end{array}
781 \right\}
782 \left[
783 \text{\LKWD{by} \VAR{step}\DF{\LIT{1}}}
784 \right]\\
785 \left.\!
786 \begin{array}{l}
787 \text{\LKWD{in}} \\
788 \text{\LKWD{on}}
789 \end{array}
790 \right\}
791 \text{\VAR{list}}
792 \left[
793 \text{\LKWD{by} \VAR{form}\DF{\kwd{cdr}}}
794 \right]\\
795 \text{\LKWD{=} \VAR{foo }}
796 \left[
797 \text{\LKWD{then} \VAR{bar}}
798 \right] \\
799 \text{\LKWD{across} \VAR{vector}}\\
800 \text{\LKWD{being}}
801 \left\{
802 \begin{array}{l}
803 \text{\LKWD{the}}\\
804 \text{\LKWD{each}}
805 \end{array}
806 \right\}%
807 \left\{
808 \begin{array}{{l}}
809 \left.\!
810 \begin{array}{l}
811 \left.\!
812 \begin{array}{l}
813 \text{\LKWD{hash-key}}\\
814 \text{\LKWD{hash-keys}}
815 \end{array}
816 \right\}%
817 \left\{
818 \begin{array}{l}
819 \text{\LKWD{of}}\\
820 \text{\LKWD{in}}
821 \end{array}
822 \right\}
823 \text{\VAR{hash }}
824 \left[
825 \text{\LKWD{using} (\LKWD{hash-value} \VAR{v})}
826 \right]\\
827 \left.\!
828 \begin{array}{l}
829 \text{\LKWD{hash-value}}\\
830 \text{\LKWD{hash-values}}
831 \end{array}
832 \right\}%
833 \left\{
834 \begin{array}{l}
835 \text{\LKWD{of}}\\
836 \text{\LKWD{in}}
837 \end{array}
838 \right\}
839 \text{\VAR{hash }}
840 \left[
841 \text{\LKWD{using} (\LKWD{hash-key} \VAR{k})}
842 \right.\\
843 \end{array}
844 \right.\\
845 \left.\!
846 \begin{array}{l}
847 \text{\LKWD{symbol\Op{s}}}\\
848 \text{\LKWD{present-symbol\Op{s}}}\\
849 \text{\LKWD{external-symbol\Op{s}}}
850 \end{array}
851 \right\}%
852 \left[
853 \left\{
854 \begin{array}{l}
855 \text{\LKWD{of}}\\
856 \text{\LKWD{in}}
857 \end{array}
858 \right\} \text{\VAR{package}\DF{\V{*package*}}}
859 \right]
860 \end{array}
861 \right.
862 \end{array}
863 \right\}_{\displaystyle{\mathbb{F}_0}}
864 }%boxed
865 \left\{
866 \text{\LKWD{and} }\boxed{\mathbb{F}_i}
867 \right\}^{\!*}\\
868 \left.\!%
869 \begin{array}{l}
870 \text{\LKWD{initially}} \\
871 \text{\LKWD{finally}}
872 \end{array}
873 \right\}
874 \text{\VAR{form}}^{+} \\
876 \end{array}
877 \right\}^{\!\!\displaystyle{*}}
878 %Bottleneck
879 \left\{
880 \begin{array}{l}
881 \text{\LKWD{repeat} \VAR{num}}\\
882 \left.\!
883 \begin{array}{l}
884 \text{\LKWD{while}}\\
885 \text{\LKWD{until}}\\
886 \text{\LKWD{always}}\\
887 \text{\LKWD{never}}\\
888 \text{\LKWD{thereis}}
889 \end{array}
890 \right\}
891 \text{\VAR{test}}\\
892 \boxed{
893 \left.\!
894 \begin{array}{l}
895 \left.\!
896 \begin{array}{l}
897 \text{\LKWD{do}}\\
898 \text{\LKWD{doing}}
899 \end{array}
900 \right\}
901 \text{\VAR{form}}^{+}\\
902 \text{\LKWD{return}}
903 \left\{
904 \begin{array}{l}
905 \text{\VAR{form}}\\
906 \text{\LKWD{it}}
907 \end{array}
908 \right.\\
909 \left.\!
910 \begin{array}{l}
911 \text{\LKWD{collect\Op{ing}}}\\
912 \text{\LKWD{append\Op{ing}}}\\
913 \text{\LKWD{nconc\Op{ing}}}
914 \end{array}
915 \right\}
916 \left\{
917 \begin{array}{l}
918 \text{\VAR{form}}\\
919 \text{\LKWD{it}}
920 \end{array}
921 \right\} [\text{\LKWD{into }\VAR{var}}]\\
922 \left.\!
923 \begin{array}{l}
924 \text{\LKWD{count\Op{ing}}}\\
925 \text{\LKWD{sum\Op{ming}}}\\
926 \text{\LKWD{maximize}}\\
927 \text{\LKWD{maximizing}}\\
928 \text{\LKWD{minimize}}\\
929 \text{\LKWD{minimizing}}
930 \end{array}
931 \right\}
932 \left\{
933 \begin{array}{l}
934 \text{\VAR{form}}\\
935 \text{\LKWD{it}}
936 \end{array}
937 \right\}
938 [\text{\LKWD{into }\VAR{n}}]
939 [\text{\VAR{type}}]\\
940 \left.\!
941 \begin{array}{l}
942 \text{\LKWD{if}}\\
943 \text{\LKWD{when}}\\
944 \text{\LKWD{unless}}
945 \end{array}
946 \right\}%
947 \text{\VAR{test }}
948 \boxed{\mathbb{S}_i}\{\text{\LKWD{and}}%
949 \boxed{\mathbb{S}_j}\}^{*}[\text{\LKWD{else}}%
950 \boxed{\mathbb{S}_k}\{\text{\LKWD{and}}%
951 \boxed{\mathbb{S}_l}\}^{*}][\text{\LKWD{end}}]
952 \end{array}
953 \right._{\!\!\!\!\displaystyle{\mathbb{S}_0}}
954 }%boxed
956 \left.\!
957 \begin{array}{l}
958 \text{\LKWD{initially}} \\
959 \text{\LKWD{finally}}
960 \end{array}
961 \right\}
962 \text{\VAR{form}}^{+}
963 \end{array}
964 \right\}^{\displaystyle{\!\!*}}
966 \!)%
967 \end{sideways}%
968 \end{center}\vspace{-1em}
969 \caption{Loop Facility, Overview.}%
970 \end{figure}
973 \begin{LIST}{1cm}
975 \IT{(\MC*{LOOP} \OPn{\VAR{form}})}
977 Simple Loop. If \VAR{form}s do
978 not include any keywords of the Loop Facility, evaluate them forever.
981 \IT{(\MC*{LOOP} \OPn{\VAR{form}})}
983 Loop Facility. If there are loop facility keywords in \VAR{form}s
984 see below and p.\ \pageref{loop-overview}.
987 \begin{LIST}{.5cm}
989 \IT{\LKWD*{named} \VAR{n}}
991 Give implicit \kwd{block} of loop a name.
994 \IT{\LKWD*{with} \VAR{var} \Op{\VAR{type}} \LKWD*{=} \VAR{foo} \Goos{\LKWD*{and}
995 \VAR{var-n} \Op{\VAR{type}} \LKWD*{=} \VAR{bar}}}
997 Initialize local variables in parallel.
1000 \IT{\Goo{\LKWD*{initially}\XOR\LKWD*{finally}} \RP{\VAR{form}}}
1002 Evaluate \VAR{form}s before begin, or after end, respectively, of iterations.
1005 \IT{\Goo{\LKWD*{for}\XOR\LKWD*{as}} \VAR{var} \Op{\VAR{type}}}
1007 Begin of iteration control clause.
1010 \begin{LIST}{.5cm}
1012 \IT{\Goo{\LKWD*{upfrom}\XOR\LKWD*{from}\XOR\LKWD*{downfrom}}
1013 \VAR{start}}
1015 Start stepping with \VAR{start}
1018 \IT{\Goo{\LKWD*{upto}\XOR\LKWD*{downto}\XOR\LKWD*{to}\XOR\LKWD*{below}\XOR\LKWD*{above}}
1019 \VAR{form}}
1021 Specify \VAR{form} as the end value for stepping.
1024 \IT{\Goo{\LKWD*{in}\XOR\LKWD*{on}} \VAR{list}}
1026 Bind \VAR{var} to successive elements/tails, respectively, of \VAR{list}.
1029 \IT{\LKWD*{by} \Goo{\VAR{step}\DF{\LIT{1}}\XOR\VAR{function}\DF{\FU{cdr}}}}
1031 Specify the (positive) decrement or increment or the
1032 \VAR{function} to apply to the list.
1035 \IT{\LKWD*{=} \VAR{foo} \Op{\LKWD*{then}
1036 \VAR{bar}\DF{\VAR{foo}}}}
1038 Bind \VAR{var} in the first iteration to \VAR{foo} and later to \VAR{bar}.
1041 \IT{\LKWD*{across} \VAR{vector}}
1043 Bind \VAR{var} to successive elements of \VAR{vector}.
1046 \IT{\LKWD*{being} \Goo{\LKWD*{the}\XOR\LKWD*{each}}}
1048 Iterate over a hash table or a package.
1051 \begin{LIST}{.5cm}
1053 \IT{\Goo{\LKWD*{hash-key}\XOR\LKWD*{hash-keys}} \Goo{\LKWD*{of}\XOR\LKWD*{in}} \VAR{hash-table}
1054 \Op{\LKWD*{using} (\LKWD*{hash-value} \VAR{value})}}
1056 Bind \VAR{var} successively to the keys of \VAR{hash-table}; bind \VAR{value} to corresponding values.
1059 \IT{\Goo{\LKWD*{hash-value}\XOR\LKWD*{hash-values}} \Goo{\LKWD*{of}\XOR\LKWD*{in}} \VAR{hash-table}
1060 \Op{\LKWD*{using} (\LKWD*{hash-key} \VAR{key})}}
1062 Bind \VAR{var} successively to the values of \VAR{hash-table}; bind \VAR{key} to corresponding keys.
1065 \IT{\Goo{\LKWD*{symbol}\XOR\LKWD*{symbols}\XOR\LKWD*{present-symbol}\XOR\LKWD*{present-symbols}\XOR\LKWD*{external-symbol}\XOR\LKWD*{external-symbols}}
1066 \Op{\Goo{\LKWD*{of}\XOR\LKWD*{in}}
1067 \VAR{package}\DF{\V{*package*}}}}
1069 Bind \VAR{var} successively to the symbols, or the present
1070 symbols, or the external symbols, respectively, of
1071 \VAR{package}.
1074 \end{LIST}
1075 \end{LIST}
1077 \IT{\LKWD*{and} \VAR{var} \Op{\VAR{type}}}
1079 Begin of another iteration control clause with variables
1080 initialized and stepped in parallel.
1083 \IT{\Goo{\LKWD*{do}\XOR\LKWD*{doing}} \RP{\VAR{form}}}
1085 Evaluate \VAR{form}s in every iteration.
1088 \IT{\LKWD*{it}}
1090 Value of \VAR{test} form of an enclosing \LKWD{if},
1091 \LKWD{when}, \LKWD{unless}, or \LKWD{else} clause.
1094 \IT{\LKWD*{return} \Goo{\VAR{form}\XOR\LKWD*{it}}}
1096 Return immediately with value of \VAR{form} or \LKWD{it}.
1099 \IT{\Goo{\LKWD*{collect}\XOR\LKWD*{collecting}}
1100 \Goo{\VAR{form}\XOR\LKWD*{it}} \Op{\LKWD*{into} \VAR{list}}}
1102 Collect values of \VAR{form} or \LKWD{it} into \VAR{list}. If no
1103 \VAR{list} is given, collect into an anonymous list which is
1104 returned after termination.
1107 \IT{\Goo{\LKWD*{append}\XOR\LKWD*{appending}\XOR\LKWD*{nconc}\XOR\LKWD*{nconcing}}
1108 \Goo{\VAR{form}\XOR\LKWD*{it}} \Op{\LKWD*{into}
1109 \VAR{list}}}
1111 Concatenate values of \VAR{form} or \LKWD{it}, which should be
1112 lists, into \VAR{list} by the means of \FU{append} or \FU{nconc},
1113 respectively. If no \VAR{list} is given, collect into an
1114 anonymous list which is returned after termination.
1117 \IT{\Goo{\LKWD*{count}\XOR\LKWD*{counting}}
1118 \Goo{\VAR{form}\XOR\LKWD*{it}} \Op{\LKWD*{into}
1119 \VAR{n}} \Op{\VAR{type}}}
1121 Count the number of times the value of \VAR{form} or of \LKWD{it} is \T.
1122 If no \VAR{n} is given, count into an anonymous variable
1123 which is returned after termination.
1126 \IT{\Goo{\LKWD*{sum}\XOR\LKWD*{summing}}
1127 \Goo{\VAR{form}\XOR\LKWD*{it}} \Op{\LKWD*{into}
1128 \VAR{sum}} \Op{\VAR{type}}}
1130 Calculate the sum of the values of \VAR{form} or of \LKWD{it}.
1131 If no \VAR{sum} is given, sum into an anonymous variable
1132 which is returned after termination.
1135 \IT{\Goo{\LKWD*{maximize}\XOR\LKWD*{maximizing}\XOR
1136 \LKWD*{minimize}\XOR
1137 \LKWD*{minimizing}} \Goo{\VAR{form}\XOR\LKWD*{it}} \Op{\LKWD*{into}
1138 \VAR{max-min}} \Op{\VAR{type}}}
1140 Determine the maximum or minimum, respectively, of the values of
1141 \VAR{form} or of \LKWD{it}.
1142 If no \VAR{max-min} is given, use an anonymous variable
1143 which is returned after termination.
1146 \IT{\Goo{\LKWD*{if}\XOR\LKWD*{when}\XOR\LKWD*{unless}} \VAR{ test}
1147 \VAR{form-i} \Goos{\LKWD*{and}
1148 \VAR{form-j}} \Op{\LKWD*{else} \VAR{form-k} \Goos{\LKWD*{and}
1149 \VAR{form-l}}} \Op{\LKWD*{end}}}
1151 If \VAR{test} returns \T, \T, or \NIL, respectively, evaluate
1152 \VAR{form-i} and \VAR{form-j}s; otherwise, evaluate \VAR{form-k}
1153 and \VAR{form-l}s. Inside \VAR{form-i} and \VAR{form-k}, the value
1154 of \VAR{test} is accessible by \LKWD*{it}.
1157 \IT{\LKWD*{repeat} \VAR{num}}
1159 Terminate \MC{loop} after \VAR{num} times; \VAR{num} is evaluated once.
1162 \IT{\Goo{\LKWD*{while}\XOR\LKWD*{until}} \VAR{test}}
1164 Continue iteration until \VAR{test} returns \NIL, or \T, respectively.
1167 \IT{\Goo{\LKWD*{always}\XOR\LKWD{never}} \VAR{test}}
1169 Terminate \MC{loop} returning \NIL\ and skipping any
1170 \LKWD*{finally} parts as soon as \VAR{test} is \NIL, or \T,
1171 respectively. Otherwise continue \MC{loop} with its default return
1172 value set to \T.
1175 \IT{\LKWD*{thereis} \VAR{test}}
1177 Terminate \MC{loop} when \VAR{test} is \T\ and return value of
1178 \VAR{test}, skipping any \LKWD*{finally} parts. Otherwise continue
1179 \MC{loop} with its default return value set to \NIL.
1182 \IT{\LKWD*{loop-finish}}
1184 Terminate \MC{loop} immediately; skip any \LKWD*{finally} parts.
1186 \end{LIST}
1187 \end{LIST}
1192 % LocalWords: pt