@@@ mess!
[sod] / doc / misc.tex
1 %%% -*-latex-*-
2 %%%
3 %%% Miscellaneous functionality
4 %%%
5 %%% (c) 2015 Straylight/Edgeware
6 %%%
7
8 %%%----- Licensing notice ---------------------------------------------------
9 %%%
10 %%% This file is part of the Sensible Object Design, an object system for C.
11 %%%
12 %%% SOD is free software; you can redistribute it and/or modify
13 %%% it under the terms of the GNU General Public License as published by
14 %%% the Free Software Foundation; either version 2 of the License, or
15 %%% (at your option) any later version.
16 %%%
17 %%% SOD is distributed in the hope that it will be useful,
18 %%% but WITHOUT ANY WARRANTY; without even the implied warranty of
19 %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 %%% GNU General Public License for more details.
21 %%%
22 %%% You should have received a copy of the GNU General Public License
23 %%% along with SOD; if not, write to the Free Software Foundation,
24 %%% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26 \chapter{Miscellaneous functionality} \label{ch:misc}
27
28 %%%--------------------------------------------------------------------------
29 \section{Utilities} \label{sec:misc.utilities}
30
31 These symbols are defined in the @|sod-utilities| package.
32
33
34 \subsection{Macro utilities}
35
36 We begin with some simple utilities which help with writing macros. Several
37 of these are standard.
38
39 \begin{describe}{mac}
40 {with-gensyms (@{ @<var> @! (@<var> @[@<name>@]) @}^*) \\ \ind
41 @<declaration>^* \\
42 @<form>^*
43 \-\nlret @<value>^*}
44 Bind each @<var> (a symbol, not evaluated) to a freshly made gensym whose
45 name is based on the corresponding @<name> (a string, evaluated), and
46 evaluate the @<form>s as an implicit @|progn| in the resulting environment.
47 If @<name> is omitted, then the name of the @<var> is used as a default; a
48 bare symbol may be written in place of a singleton list.
49 \end{describe}
50
51 \begin{describe}{mac}
52 {once-only (@[[ :environment @<env> @]]
53 @{ @<var> @! (@<var> @[@<value-form>@]) @}^*) \\ \ind
54 @<declaration>^* \\
55 @<form>^*
56 \-\nlret @<result-form>}
57 This is a helper to ensure that macro expansions evaluate their arguments
58 exactly once each, in the correct order.
59
60 Each @<var> is bound to an appropriate value (often a gensym) and then the
61 @<form>s are evaluated as an implicit @|progn| in the resulting environment
62 to produce an output form. This output form is then enclosed in one or
63 more binding forms to produce a @<result-form>. When the @<result-form> is
64 evaluated, the behaviour will be as if each @<value-form> is evaluated
65 exactly once each, in order, and each value is captured in the
66 corresponding @<var>.
67
68 A simple @|once-only| expansion might look something like
69 \begin{prog}
70 (let (\=(@<var>_1 (gensym)) \\
71 \>\qquad\vdots \\
72 \>(@<var>_n (gensym))) \\ \ind
73 `(let (\=(,@<var>_1 ,@<value-form>_1) \\
74 \>\qquad\vdots \\
75 \>(,@<var>_n ,@<value-form>_n)) \\ \ind
76 @<declaration>_1 \dots\ @<declaration>_m \\
77 @<form>_1 \dots\ @<form>_\ell))
78 \end{prog}
79 However, if @|once-only| can determine that some @<value-form> is a
80 constant (e.g., it is @|quote|d, self-evaluating, or reported as
81 @|constantp| in the given environment @<env>), then it need not allocate a
82 gensym: it can instead bind the @<var> directly to the constant value.
83
84 If a @<value-form> is omitted, then the value of the corresponding @<var>
85 is used. It is conventional usage for a macro to wrap @|once-only| around
86 its body so as to convert the arguments which it should evaluate into safe
87 gensyms capturing their runtime values. (Note that the simple expansion
88 given above can't do this correctly.) A bare symbol may be written in
89 place of a singleton list.
90 \end{describe}
91
92 \begin{describe}{fun}
93 {parse-body @<body> \&key :docp :declp
94 @> @<doc-string> @<declarations> @<body-forms>}
95 Parse the @<body> into a @<doc-string>, some @<declaration>s, and a list of
96 @<body-forms>.
97
98 The @<body> is assumed to have the general syntax
99 \begin{prog}
100 @[[ @<doc-string> @! @<declaration>^* @]] \\
101 @<form>^*
102 \end{prog}
103 A @<doc-string> is permitted if and only if @<docp> is non-nil, and
104 declarations are permitted if and only if @<declp> is non-nil; both are
105 true by default.
106
107 Each return value is a list, which is empty if the corresponding part of
108 the input @<body> is missing. Specifically:
109 \begin{itemize}
110 \item @<doc-string> is either nil, or a singleton list containing a string;
111 \item @<declarations> is either nil, or a singleton list containing a
112 @|(declare \dots)| form gathering up all of the individual
113 @<declaration>s within the @<body>; and
114 \item @<body-forms> is a list of the remaining forms in the @<body>.
115 \end{itemize}
116 Thus, the parsed body-parts can conveniently be spliced into a macro
117 expansion using @|,@@|.
118 \end{describe}
119
120 \begin{describe}{fun}{symbolicate \&rest @<symbols> @> @<symbol>}
121 Return the symbol, interned in the current @|*package*|, whose name is the
122 concatenation of the names of the given @<symbols>.
123 \end{describe}
124
125
126 \subsection{Locatives}
127
128 A \emph{locative} is a value which remembers where another value is stored,
129 -- whether it's in a variable, an array element, a structure slot, a hash
130 table, etc.\ -- and can modify and retrieve it.
131
132 Some Lisp systems have highly efficient locatives which actually keep track
133 of the machine addresses of the places to which they refer. Common Lisp does
134 not implement true locatives of this kind, but something sufficiently useful
135 can be synthesized.
136
137 These locatives can't usefully be compared. It should be possible to compare
138 true locatives, such that two locatives compare equal if and only if they
139 refer to the same place; but that doesn't work for these locatives.
140
141 \begin{describe}{cls}{locative}
142 The type of locative objects.
143 \end{describe}
144
145 \begin{describe}{fun}{locativep @<object> @> @<generalized-boolean>}
146 Return non-nil if and only if @<object> is a locative.
147 \end{describe}
148
149 \begin{describe}{mac}{locf @<place> @> @<locative>}
150 Return a fresh locative capturing the @<place>, which may be any expression
151 usable as the first operand to @|setf|.
152 \end{describe}
153
154 \begin{describe*}
155 {\dhead{fun}{ref @<locative> @> @<value>}
156 \dhead{fun}{setf (ref @<locative>) @<value>}}
157 Retrieve and return the current value stored in the place captured by the
158 @<locative>. With @|setf|, store the new @<value> in the place captured by
159 the @<locative>.
160 \end{describe*}
161
162 \begin{describe}{mac}
163 {with-locatives
164 @{ @<var> @! (@{ @<var> @!
165 (@<var> @[@<locative>@]) @}^*) @} \\ \ind
166 @<declaration>^* \\
167 @<form>^*
168 \-\nlret @<values>^*}
169 This is a macro which hides the use of locatives from its caller using
170 symbol-macros.
171
172 Each @<locative> should be an expression which evaluates to a locative
173 value (not a general place). These are evaluated once each, left to
174 right. The @<form>s are then evaluated as an implicit @|progn|, with each
175 @<var> defined as a symbol macro which will retrieve -- or, with @|setf|,
176 modify -- the value referred to by the corresponding locative.
177
178 If a @<locative> is omitted, it defaults to the value of @<var>; a
179 bare symbol may be used in place of a singleton list.
180 \end{describe}
181
182
183 \subsection{Anaphorics}
184
185 An anaphoric macro implicitly binds a well-known name to a value of interest,
186 in the course of doing something else. The concept was popularized by Paul
187 Graham \cite{graham-1993:on-lisp}.
188
189 The macros described here all bind the variable @|it|.
190
191 \begin{describe}{sym}{it}
192 The symbol @|it| is exported by the @|sod-utilities| package.
193 \end{describe}
194
195 \begin{describe}{mac}
196 {aif @<condition> @<consequent> @[@<alternative>@] @> @<value>^*}
197 Evaluate the @<condition>. If @<condition> is non-nil, then bind @|it| to
198 the resulting value and evaluate the @<consequent>, returning all of its
199 values. Otherwise, evaluate @<alternative>, returning all of its values.
200 \end{describe}
201
202 \begin{describe}{mac}{aand @<form>^* @> @<value>^*}
203 Evaluate each @<form> in turn. If any @<form> evaluates to nil, then stop
204 and return nil. Each form except the first is evaluated with @|it| bound
205 to the (necessarily non-nil) value of the previous form. If all but the
206 last form evaluate non-nil, then return all the values of the final form.
207 \end{describe}
208
209 (No @|aor| is provided, since @|it| would necessarily be bound to nil.)
210
211 \begin{describe}{mac}{awhen @<condition> @<form>^* @> nil}
212 If @<condition> evaluates to a non-nil value, bind @|it| to that value, and
213 evaluate the @<form>s as an implicit @|progn|. Otherwise, return nil.
214 \end{describe}
215
216 \begin{describe}{mac}{acond @{ (@<condition> @<form>^*) @}^* @> @<value>^*}
217 Evaluate each @<condition> in turn, until one of them produces a non-nil
218 value. If the @<condition> is followed by one or more @<form>s, then bind
219 @|it| to the non-nil value of the @<condition> and evaluate the @<form>s as
220 an implicit @|progn|; otherwise, simply return the value of the
221 @<condition>. If no @<condition> produces a non-nil value then return nil.
222 \end{describe}
223
224 \begin{describe*}
225 {\dhead{mac}{acase @<scrutinee>
226 @{ (@{ @<case> @! (@<case>^*) @} @<form>^*) @}^*
227 @> @<value>^*}
228 \dhead{mac}{aecase @<scrutinee>
229 @{ (@{ @<case> @! (@<case>^*) @} @<form>^*) @}^*
230 @> @<value>^*}
231 \dhead{mac}{atypecase @<scrutinee> @{ (@<type> @<form>^*) @}^*
232 @> @<value>^*}
233 \dhead{mac}{aetypecase @<scrutinee> @{ (@<type> @<form>^*) @}^*
234 @> @<value>^*}}
235 These are like the Common Lisp macros @|case|, @|ecase|, @|typecase|, and
236 @|etypecase|, except that @|it| is bound to the value of the @<scrutinee>
237 while evaluating the matching @<form>s.
238 \end{describe*}
239
240 \begin{describe}{mac}{asetf @{ @<place> @<value> @}^* @> @<value>^*}
241 For each @<place> and @<value> in turn: bind @|it| to the current value of
242 the @<place>, evaluate the @<value> expression, and store the resulting
243 value back in the @<place>. Return the @<value>(s) stored by the final
244 pair: there may be more than one value, e.g., if @<place> is a @|values|
245 form.
246
247 For example, @|(asetf @<place> (1+ it))| is almost equivalent to @|(incf
248 @<place>)|, even if evaluating @<place> has side-effects.
249 \end{describe}
250
251
252 \subsection{Metaobject protocol utilities}
253
254 The following utilities make use of the introspection features of the CLOS
255 metaobject protocol.
256
257 \begin{describe}{gf}{instance-initargs @<instance> @> @<initargs-list>}
258 Return a fresh list of plausible initargs for the given @<instance>.
259
260 The default method should work for most classes, but may be overridden to
261 cope with special effects.
262
263 \begin{describe}{meth}{standard-object}
264 {instance-initargs (@<instance> standard-object) @> @<initargs-list>}
265 The default method works by digging through the instance's class's slot
266 definitions and enquiring about their initargs. Initargs which are
267 handled by methods on @|shared-initialize| or similar generic functions
268 won't be discovered.
269 \end{describe}
270 \end{describe}
271
272 \begin{describe*}
273 {\dhead{fun}{copy-instance @<instance> \&rest @<initargs>
274 @> @<new-instance>}
275 \dhead{gf}{copy-instance-using-class @<class> @<instance>
276 \&rest @<initargs>
277 @> @<new-instance>}}
278 The @|copy-instance| function creates and returns a fresh copy of a given
279 @<instance>, possibly modifying it according to the given @<initargs>.
280
281 It immediately calls @|copy-instance-using-class|, calling it with the
282 instance's class and the instance itself, and simply returns the result of
283 that generic function.
284
285 The default method on @|copy-instance-using-class| should work for most
286 classes, but may be overridden to cope with special effects.
287
288 \begin{describe}{meth}{standard-class}
289 {copy-instance-using-class \=(@<class> standard-class) @<instance> \\
290 \>\&rest initargs
291 \nlret @<new-instance>}
292 The default method works as follows.
293 \begin{enumerate}
294 \item Allocate a fresh instance of @<class>, using @|allocate-instance|.
295 \item For each slot defined by @<class>, if that slot is bound in the
296 original instance, then set the corresponding slot in the new instance
297 to the same value.
298 \item Call @|shared-initialize| on the new instance, providing it the
299 given list of @<initargs>, but inhibiting the usual initialization of
300 slots from their initforms.
301 \item Return the new instance.
302 \end{enumerate}
303 \end{describe}
304 \end{describe*}
305
306 \begin{describe}{fun}
307 {find-eql-specialized-method @<function> @<arg> @<objcet>}
308 Find and return a method defined on a generic @<function> whose @<arg>th
309 argument (counting from zero) is @|eql|-specialized on the givan
310 @<object>. If there is no such method on @<function> then return @|nil|.
311 If there are multiple such methods, return one of them arbitrarily.
312 \end{describe}
313
314 \begin{describe*}
315 {\dhead{gf}{generic-function-methods @<generic-function> @> @<list>}
316 \dhead{gf}{method-specializers @<method> @> @<list>}
317 \dhead{cls}{eql-specializer}
318 \dhead{gf}{eql-specializer-object @<specializer> @> @<value>}}
319 These are precisely the MOP functions and class: the symbols are
320 re-exported for portability, because different Lisp systems define these
321 symbols in different packages.
322 \end{describe*}
323
324
325 \subsection{Other CLOS utilities}
326
327 Some other minor CLOS utilities.
328
329 \begin{describe}{mac}
330 {default-slot (@<instance> @<slot> @[@<slot-names>@]) \\ \ind
331 @<form>^*}
332 This macro is useful in methods (usually @|:after| methods) on
333 @|shared-initialize|, to set slots to some sensible default values in the
334 case where no suitable initarg was given, and default initialization is too
335 complicated to be done using an initform.
336
337 Set a slot to a default value, obeying the @|shared-initialize| protocol.
338 If (a) the named @<slot> of @<instance> is unbound, and (b) either
339 @<slot-names> is @|t|, or @<slot> is a member of the list @<slot-names>,
340 then evaluate the @<form>s as an implicit @|progn| and store their
341 value in the @<slot>. Otherwise do nothing.
342
343 The @<instance>, @<slot>, and @<slot-names> (if any) are evaluated once
344 each, left-to-right.
345 \end{describe}
346
347 \begin{describe}{mac}
348 {define-on-demand-slot @<class> @<slot> (@<instance>) \\ \ind
349 @[[ @<declaration>^* @! @<doc-string> @]] \\
350 @<form>^*}
351 This macro makes slots with delayed initialization: rather than being
352 set when the object is constructed, the slot's initial value is only
353 calculated when it's first requested. This is useful if calculating the
354 slot value is expensive and often not required, or if it's not possible to
355 initialize the slot along with the rest of the object because of dependency
356 cycles.
357
358 The macro arranges things as follows. Whenever @|slot-value| is called
359 (possibly indirectly, via a reader function) to read the named @<slot> (a
360 symbol, not evaluated) on an (indirect) instance of @<class>, but the slot
361 is unbound, then @<instance> is bound to the instance in question and the
362 @<form>s are evaluated as an implicit @|progn| within the lexical
363 environment of the @|define-on-demand-slot| call, and the resulting value
364 is used as the initial value of the slot. (Furthermore, a block named
365 @<slot> is wrapped around the @<form>s, allowing an early return if that
366 should be useful.)
367
368 This macro currently works by defining a method on @|slot-unbound|.
369 \end{describe}
370
371
372 \subsection{Building lists}
373
374 Many Lisp functions end up constructing lists. In simple cases, a function
375 like @|mapcar| will just do the job directly. In more complex cases, a
376 common idiom is to build the list using @|push| for each element in turn; but
377 a list built this way ends up in the wrong order, so an additional pass,
378 usually using @|nreverse|, is necessary to fix it.
379
380 A `list builder' is an object which can be used to construct a list in the
381 right order. (Currently, a list-builder is simply a cons cell, whose cdr
382 points to the first cons-cell of the list, and whose car points to its last
383 cons; an empty list-builder is a cons whose cdr is nil and whose car is the
384 cons itself, i.e., @|\#1=(\#1\# . nil)|.)
385
386 \begin{describe}{fun}{make-list-builder \&optional @<initial> @> @<builder>}
387 Return a fresh new list-builder, initially containing no items.
388 \end{describe}
389
390 \begin{describe}{fun}{lbuild-add @<builder> @<item> @> @<builder>}
391 Add @<item> to the end of the list being constructed in @<builder>.
392 \end{describe}
393
394 \begin{describe}{fun}{lbuild-add-list @<builder> @<list> @> @<builder>}
395 Append @<list> to the list being constructed in @<builder>. The list is
396 \emph{not} copied: adding further items to the list will clobber cdr of its
397 final cons-cell.
398 \end{describe}
399
400 \begin{describe}{fun}{lbuild-list @<builder> @> @<list>}
401 Return the list being constructed in the @<builder>.
402
403 It is permitted to continue adding items to the list: this will mutate the
404 list in-place. Often, this is what you want. For example, one might write
405 an analogue to @|pushnew| like this:
406 \begin{prog}
407 (defun lbuild-add-new
408 (builder item \&key key test test-not \&rest keywords) \\ \ind
409 (declare (ignore key test test-not)) \\
410 (when (apply \#'member item (lbuild-list builder)
411 keywords) \\ \ind
412 (lbuild-add builder item)))
413 \end{prog}
414 \end{describe}
415
416
417 \subsection{Merging lists}
418
419 The following machinery merges lists representing a partial order. The
420 primary use for this is in computing class precedence lists during class
421 finalization. By building the input lists and choosing the tie-breaking
422 @<pick> function appropriately, many different linearization algorithms can
423 be implemented fairly easily using @|merge-lists| below.
424
425 \begin{describe*}
426 {\dhead{cls}
427 {inconsistent-merge-error (error) \&key :candidates :present}
428 \dhead{gf}{merge-error-candidates @<error> @> @<list>}
429 \dhead{gf}{merge-error-present-function @<error> @> @<function>}}
430 The @|inconsistent-merge-error| condition class used to represent a failure
431 of the \descref{fun}{merge-lists}[function].
432
433 The @<candidates> are a list of offending items from the input lists, in
434 some order: the error is reporting that the function has failed because it
435 is not possible to order the items listed in @<candidates> in any way
436 without being inconsistent with at least one of the input lists. There is
437 no default.
438
439 The @<present> function is used to convert the input items into
440 human-readable descriptions (printed using @|princ|); the default is
441 @|identity|, which will simply print the items in a `friendly' format.
442 (Using @|prin1-to-string| would print their machine-readable escaped forms
443 instead.)
444
445 The functions @|merge-error-candidates| and @|merge-error-present-function|
446 respectively retrieve the candidates list and presentation function
447 assigned to a condition when it was created.
448 \end{describe*}
449
450 \begin{describe}{fun}
451 {merge-lists @<lists> \&key :pick :test :present @> @<list>}
452 Return a merge of the @<lists>, considered as partial orderings.
453
454 In more detail: @<lists> should be a list of lists. Each distinct item, as
455 determined by the @<test> function (by default, @|eql|) appears in the
456 result list exactly once. Furthermore, if, in some input list, an item $x$
457 appears earlier than a different item $y$, then $x$ will also precede $y$
458 in the output list.
459
460 If the input lists contradict each other (e.g., list $A$ has $x$ before
461 $y$, but list $B$ has $y$ before $x$), then an error of type
462 @|inconsistent-merge-error| is signalled, with the offending items attached
463 as candidates, and the function @<present> (by default, @|identity|) as the
464 presentation function.
465
466 Frequently, a collection of input lists has multiple valid merges.
467 Whenever @|merge-lists| must decide between two or more equally good
468 candidates, it calls the @<pick> function to choose one of them.
469 Specifically, it invokes @|(funcall @<pick> @<candidates>
470 @<merge-so-far>)|, where @<candidates> are the items it needs to choose
471 between, and @<merge-so-far> is the currently determined prefix of the
472 final merge. The order of items in the @<candidates> list reflects their
473 order in the input lists: item $x$ precedes item $y$ in @<candidates> if
474 any only if an occurrence of $x$ appears in an earlier input list than
475 $y$. (This completely determines the order of candidates: if two items
476 appear in the same list, then that list would have ordered them and we
477 wouldn't have to call @<pick> to break the tie.) The default @<pick>
478 function simply chooses the item appearing in the earliest list, i.e.,
479 effectively
480 \begin{prog}
481 (lambda (candidates merge-so-far) \\ \ind
482 (declare (ignore merge-so-far)) \\
483 (car candidates))
484 \end{prog}
485 \end{describe}
486
487
488 \subsection{Other list utilities}
489
490 \begin{describe}{fun}
491 {mappend @<function> @<list> \&rest @<more-lists> @> @<result-list>}
492 Return the result of appending @<list> and @<more-lists>, in order. All
493 but the final list are copied into the @<result-list>; the last one is used
494 as-is.
495 \end{describe}
496
497 \begin{describe}{mac}
498 {categorize (\=@<item-var> @<items>
499 @[[ :bind (@{ @<var> @!
500 (@<var> @[@<value>@]) @}^*) @]])
501 \\ \ind\ind
502 (@{ (@<cat-var> @<cat-predicate>) @}^*) \-\\
503 @<declaration>^* \\
504 @<form>^*
505 \-\nlret @<value>^*}
506 Partition an input list of @<items> according to the @<cat-predicate>s.
507
508 First, @<items> is evaluated, to yield a list. The @<item-var> is bound,
509 an empty list is created for each @|(@<cat-var> @<cat-predicate>)| pair,
510 and an iteration is begun. For each item in the list in turn is assigned
511 to @<item-var>; then, the bindings given by the @|:bind| keyword are
512 performed, as if by @|let*|; and the @<cat-predicate>s are evaluated in the
513 resulting environment, one by one, until one of them returns non-nil. When
514 this happens, the item is added to the corresponding list. If no predicate
515 matches the item, an error is signalled.
516
517 Once this iteration is complete, each @<cat-var> is bound to its
518 corresponding completed list, and the body @<form>s are evaluated in the
519 resulting environment (which does not include @<item-var>), as an implicit
520 @|progn|, and the macro yields the values of the final @<form>.
521 \end{describe}
522
523 \begin{describe}{fun}{partial-order-minima @<items> @<order> @> @<list>}
524 Return a list of minimal items from the list @<items> according to a
525 non-strict partial order defined by the function @<order>: @|(funcall
526 @<order> $x$ $y$)| should return non-nil if and only if $x \preceq y$ in
527 the partial order.
528 \end{describe}
529
530 \begin{describe}{fun}{cross-product \&rest @<pieces>}
531 Return the cross product of the @<pieces>.
532
533 Each arguments may be a list, or a (non-nil) atom, which is equivalent to a
534 singleton list containing just that atom. Return a list of all possible
535 lists which can be constructed by taking one item from each argument list
536 in turn, in an arbitrary order.
537 \end{describe}
538
539 \begin{describe}{fun}
540 {find-duplicates @<report> @<sequence> \&key :key :test}
541 Call @<report> on each pair of duplicate items in a @<sequence>.
542 Duplicates are determined according to the @<key> (by default @|identity|)
543 and @<test> (by default @|eql|) functions, in the usual way: two items $x$
544 and $y$ are considered equal if and only if @|(funcall @<test> (funcall
545 @<key> $x$) (funcall @<key> $y$))| returns non-nil.
546
547 The @<report> function is called as @|(funcall @<report> @<duplicate>
548 @<previous>)|. Duplicates are reported in order; the @<previous> item is
549 always the first matching item in the sequence.
550
551 This function will work for arbitrary @<test> functions, but it will run
552 much more efficiently if @<test> is @|eq|, @|eql|, @|equal|, or @|equalp|,
553 because it can use hash-tables. (The generic implementation for lists is
554 especially inefficient.)
555 \end{describe}
556
557
558 \subsection{Position tracking}
559
560 The following functions are used to maintain file positions: see
561 \xref{sec:parsing.floc}. Columns are counted starting from zero at the far
562 left. (No particular origin is needed for line numbers.) Newlines, vertical
563 tabs, and form-feeds all move to the start of the next line; horizontal tabs
564 move to the next multiple of eight columns; other characters simply advance
565 to the next column.
566
567 \begin{describe}{fun}
568 {update-position @<character> @<line> @<column>
569 @> @<new-line> @<new-column>}
570 Assume that we found @<character> at a particular @<line> and @<column> in
571 a file: return the @<new-line> and @<new-column> for the next character.
572 \end{describe}
573
574 \begin{describe}{fun}
575 {backtrack-position @<character> @<line> @<column>
576 @> @<old-line> @<old-column>}
577 Assume that we are currently at a particular @<line> and @<column> in a
578 file, and wish to \emph{unread} @<character>: return an @<old-line> and
579 @<old-column> at which we might plausibly re-read the character, so that
580 the next call to \descref{fun}{update-position} will return us to @<line>
581 and @<column>. (Specifically, the @<old-column> will likely be wrong if
582 @<character> is a horizontal tab. It is expected that this won't matter:
583 the purpose of this function is to set things up so that the
584 @|update-position| call that will accompany re-reading the character will
585 return the correct values, rather than to use the @<old-line> and
586 @<old-column> for any other purpose.)
587 \end{describe}
588
589
590 \subsection{Object printing}
591
592 \begin{describe}{mac}
593 {maybe-print-unreadable-object
594 (@<object> @<stream>
595 @[[ :type @<type> @!
596 :identity @<identity> @]]) \\ \ind
597 @<declaration>^* \\
598 @<form>^*}
599 If @|*print-escape*| is nil, then simply evaluate the @<form>s as an
600 implicit @|progn|; otherwise, print an `unreadable' object, as if by
601 \begin{prog}
602 (print-unreadable-object
603 (@<object> @<stream>
604 @[:type @<type>@]
605 @[:identity @<identity>@]) \\ \ind
606 @<form>^*)
607 \end{prog}
608 \end{describe}
609
610 \begin{describe}{fun}{print-ugly-stuff @<stream> @<func> @> @<value>^*}
611 If @<stream> is a pretty-printing stream, then print a mandatory newline,
612 and call @<func> on the underlying non-pretty-printing stream. If
613 @<stream> is not a pretty-printing stream, then simply call @<func> on
614 @<stream> directly.
615
616 The main purpose for this is to be able to access features of the
617 underlying stream which a pretty-printing stream can't proxy. Most
618 notably, this is used by C fragment output, which takes advantage of an
619 underlying \descref{cls}{position-aware-output-stream} to print @|\#line|
620 directives, so that a C~compiler will blame the original fragment in the
621 Sod module source rather than the generated C code.
622 \end{describe}
623
624
625 \subsection{Condition utilities}
626
627 The following definitions are useful when working with conditions.
628
629 \begin{describe}{cls}
630 {simple-control-error (control-error simple-error)
631 \&key :format-control :format-arguments}
632 This is the obvious multiply-inherited subclass of @|control-error| whose
633 print form is determined by a @<format-control> and a @<format-arguments>
634 list.
635 \end{describe}
636
637 \begin{describe}{fun}
638 {designated-condition
639 \=@<default-type> @<datum> @<arguments> \\
640 \>\&key :allow-pointless-arguments
641 \nlret @<condition>}
642 Creates and returns a condition object of @<default-type>, given a
643 condition designator @<datum> and @<arguments>.
644
645 The Common Lisp specification carefully explains how a `datum' and an
646 argument list together form a `condition designator', and how such a pair
647 are to be converted into a condition object with some default type, but
648 there's no mechanism provided to simply do this task. (Functions like
649 @|error| and @|signal| implicitly, but have possibly-undesirable
650 side-effects, and don't allow control over the default type.)
651
652 \begin{itemize}
653
654 \item If @<datum> is a condition object, then the designated condition is
655 simply @<datum>. In this case, if @<arguments> is not an empty list and
656 @<allow-pointless-arguments> is nil (the default), an error is signalled;
657 otherwise, the @<arguments> are ignored.
658
659 \item If @<datum> is a symbol, then the designated condition is constructed
660 by calling
661 \begin{prog}
662 (apply \#'make-condition @<datum> @<arguments>)
663 \end{prog}
664
665 \item If @<datum> is a string or function (i.e., a `format-control'), then
666 the designated condition is constructed by calling
667 \begin{prog}
668 (make-condition \=@<default-type> \\
669 \>:format-control @<datum> \\
670 \>:format-arguments @<arguments>)
671 \end{prog}
672
673 \item Otherwise the designator is malformed, and an error is signalled.
674 \end{itemize}
675 \end{describe}
676
677 \begin{describe}{fun}
678 {invoke-associated-restart @<restart> @<condition> \&rest @<arguments>}
679 Invoke the active restart named @<restart>, associated with the given
680 @<condition>, passing a list of @<arguments>.
681
682 The function attempts to find and invoke a restart with the given name. If
683 @<condition> is non-nil, then it searches among restarts associated with
684 that specific condition, and restarts associated with no condition; if
685 @<condition> is nil, then it searches among all restarts.
686
687 If a matching restart is found, it is invoked, passing the @<arguments>
688 list. Otherwise, an error (of class @|control-error|) is signalled.
689 \end{describe}
690
691 \begin{describe*}
692 {\dhead{cls}{enclosing-condition (condition) \&key :condition}
693 \dhead{gf}{enclosed-condition @<enclosing-condition> @> @<condition>}}
694 An @|enclosing condition| is a condition which contains another condition
695 within it. Objects of type @|enclosing-condition| are used to add
696 additional information to an existing condition, or to alter the type of a
697 condition without losing information.
698
699 When an @|enclosing-condition| is constructed, the @<condition> argument
700 names the existing condition to be enclosed. This enclosed condition can
701 be retrieved by calling @|enclosed-condition|.
702 \end{describe*}
703
704 \begin{describe}{cls}{information (condition) \&key}
705 A condition of class @|information| conveys information which might be of
706 interest, but does not of itself indicate that anything is wrong.
707
708 Within a compiler, @|information| conditions may be signalled in order to
709 present the user with additional diagnostic information about a recently
710 reported error.
711 \end{describe}
712
713 \begin{describe}{cls}
714 {simple-information (simple-condition information) \\ \ind
715 \&key :format-control :format-arguments}
716 This is the obvious multiply-inherited subclass of @|information|
717 whose print-representation is determined by a @<format-control> and a
718 @<format-arguments> list.
719 \end{describe}
720
721 \begin{describe*}
722 {\dhead{fun}{info @<datum> \&rest @<arguments> @> @<flag>}
723 \dhead{rst}{noted}
724 \dhead{fun}{noted \&optional @<condition>}}
725 The @|info| function establishes a restart named @|noted| and signals a
726 condition of default type @|simple-information|, designated by the @<datum>
727 and @<arguments>. The @|info| function returns non-nil if and only if the
728 associated @|noted| restart was invoked.
729
730 The @|noted| restart accepts no arguments.
731
732 The @|noted| function finds and invokes a @|noted| restart: if @<condition>
733 is non-nil, then only the restart associated with that condition (and those
734 not associated with any condition) are considered; otherwise, all
735 conditions are considered.
736 \end{describe*}
737
738 \begin{describe}{fun}
739 {promiscuous-cerror @<continue-string> @<datum> \&rest @<arguments>}
740 Establish a @|continue| restart and signal an error of default type
741 @|simple-error|, designated by @<datum> and @<arguments>. The restart's
742 report format is determined by @<continue-string> and the @<arguments>.
743
744 Some implementations of @|cerror| associate the @|continue| restart which
745 they establish with the condition they signal. This interferes with
746 special effects -- specifically, enclosing the signalled condition and
747 resignalling it. The @|promiscuous-cerror| function carefully avoids
748 associating its restart with the condition.
749 \end{describe}
750
751 \begin{describe}{fun}{cerror* @<datum> \&rest @<arguments>}
752 A simplified version of \descref{fun}{promiscuous-cerror} which uses the
753 hardcoded string @|Continue| for the restart. This makes calling the
754 function more similar to other condition-signalling functions, at the
755 expense of some usability in environments which don't continue after
756 continuable errors automatically.
757 \end{describe}
758
759
760 \subsection{Very miscellaneous utilities}
761
762 \begin{describe}{fun}
763 {whitespace-char-p @<character> @> @<generalized-boolean>}
764 Return non-nil if and only if @<character> is a whitespace character.
765
766 A character is whitespace if @|(peek-char t @<stream>)| would skip it.
767 \end{describe}
768
769 \begin{describe}{fun}
770 {frob-identifier @<string> \&key :swap-case :swap-hyphen
771 @> @<frobbed-string>}
772 Return a `frobbed' version of the identifier @<string>. Two different
773 transformations can be applied.
774
775 \begin{itemize}
776
777 \item If @<swap-case> is non-nil (the default), and the letters in
778 @<string> are either all uppercase or all lowercase, then switch the case
779 of all of the letters.
780
781 \item If @<swap-hyphen> is non-nil (the default), and @<string> contains
782 either hyphens @`--' or underscores @`_', but not both, then replace the
783 hyphens by underscores or \emph{vice-versa}.
784
785 \end{itemize}
786
787 (These are the `obvious' transformations to convert a C identifier into a
788 Lisp symbol.)
789
790 Some examples:
791 \begin{itemize}
792 \item @|(frob-identifier "foo")| $\Longrightarrow$ @|"FOO"|
793 \item @|(frob-identifier "FOO")| $\Longrightarrow$ @|"foo"|
794 \item @|(frob-identifier "FooBar")| $\Longrightarrow$ @|"FooBar"|
795 \item @|(frob-identifier "Foo-Bar")| $\Longrightarrow$ @|"Foo_Bar"|
796 \item @|(frob-identifier "Foo_Bar")| $\Longrightarrow$ @|"Foo-Bar"|
797 \item @|(frob-identifier "foo_bar")| $\Longrightarrow$ @|"FOO-BAR"|
798 \item @|(frob-identifier "foo_bar" :swap-hyphen nil)| $\Longrightarrow$
799 @|"FOO_BAR"|
800 \item @|(frob-identifier "foo_bar" :swap-case nil)| $\Longrightarrow$
801 @|"foo-bar"|
802 \item @|(frob-identifier "foo_bar" :swap-case nil :swap-hyphen nil)|
803 $\Longrightarrow$ @|"foo_bar"|
804 \end{itemize}
805 \end{describe}
806
807 \begin{describe}{fun}
808 {compose @<functions> @> @<function>}
809 Return the left-to-right composition zero or more @<functions>.
810
811 Let $f_1$, $f_2$, \ldots, $f_n$ be functions, and let $g = @|(compose $f_1$
812 $f_2$ $\cdots$ $f_n$)|$ is their composition. If $g$ is applied to
813 arguments, the effect is as follows: first, $f_1$ is applied to the
814 arguments, yielding some value; $f_2$ is applied to this value, yielding a
815 second value; and so on, until finally the value yielded by $f_n$ is
816 returned as the result of $g$. Note that this is the reverse of the usual
817 mathematician's convention, but the author finds this ordering
818 significantly easier to work with:
819 \[ g = f_n \circ \cdots \circ f_2 \circ f_1 \]
820
821 If any of the input functions return multiple values then \emph{all} of the
822 values are passed on to the next function in the list. (If the last
823 function returns multiple values then all of the values are returned from
824 the composition.
825
826 The result of composing no functions is a function which simply returns all
827 of its arguments as values; essentially, $@|(compose)| \equiv
828 @|\#'values|$.
829 \end{describe}
830
831 \begin{describe}{mac}{defvar-unbound @<name> @<documentation> @> @<name>}
832 Define a variable called @<name>, with a @<documentation> string.
833
834 The Common Lisp @|defvar| macro accepts both an initial value and a
835 doc-string as optional arguments, in that order, with the result that it's
836 not possible to define a variable and establish a documentation string for
837 it without also giving it an initial value. The @|defvar-unbound| macro,
838 on the other hand, never changes the symbol's variable-value.
839 \end{describe}
840
841 \begin{describe}{mac}
842 {dosequence (@<var> @<sequence>
843 @[[ :start @<start> @! :end @<end> @!
844 :indexvar @<index-var> @]]) \\ \ind
845 @<declaration>^* \\
846 @{ @<tag> @! @<statement> @}^*}
847 Iterate over a @<sequence>. Common Lisp has a rich collection of iteration
848 primitives, and a rich collection of functions for working with sequences,
849 but no macro for iterating over the items of a sequence.
850
851 First, the @<sequence> is evaluated. If @<start> and/or @<end> are
852 provided, they are also evaluated (in that order), which should produce
853 integers; @<end> may be also be nil. If not provided, or nil (in the case
854 of @<end>), @<start> and @<end> default respectively to zero and the length
855 of the @<sequence>. For each item in the sequence between the @<start> and
856 @<end> positions (i.e., each item in @|(subseq @<sequence> @<start>
857 @<end>)|, in order, the body is evaluated as an implicit @|tagbody|, with
858 @<var> bound to the item and, if provided, @<index-var> bound to the item's
859 index. It is not specified whether the @<var> and @<index-var> are
860 let-bound or mutated in each iteration.
861
862 Unlike other Common Lisp @|do|\dots\ forms, there is no `result' form.
863 \end{describe}
864
865 \begin{describe}{mac}
866 {define-access-wrapper @<from> @<to>
867 @[[ :read-only @<read-only-flag> @]]}
868 Define @<from> as a function of one argument, so that @|(@<from> @<thing>)|
869 is equivalent to @|(@<to> @<thing>)|. If @<read-only-flag> is nil (the
870 default), then also define @|(setf @<from>)| so that @|(setf (@<from>
871 @<thing>) @<value>)| is equivalent to @|(setf (@<to> @<thing>) @<value>)|.
872
873 In a @|defstruct| form, the accessor function names are constructed based
874 on the structure name and slot names. The structure name and accessor
875 names are part of the exported interface, but the slot names ideally
876 shouldn't be. This causes a problem when the slot name which will lead to
877 the right accessor is already an external symbol in some package. You can
878 solve this problem by choosing an internal name for the symbol, and then
879 using this macro to define an accessor function with the name that you
880 want, in terms of the accessor that @|defstruct| made.
881 \end{describe}
882
883 \begin{describe}{fun}
884 {distinguished-point-shortest-paths @<root> @<neighbours-func>
885 @> @<list>}
886 Calculate the shortest path from the @<root> to each node reachable from it
887 in a directed graph. The nodes of the graph can be any kind of object;
888 they will be compared using @|eql|.
889
890 The @<neighbours-func> should be a function which, given a node~$v$ as its
891 only argument, returns a list of cons cells @|($v'$ . $c'$)|, one for each
892 node~$v'$ adjacent to $v$, indicating the cost $c'$ of traversing the arc
893 from $v$ to $v'$.
894
895 The return value is a list of cons cells @|($c$ . $p$)|, where $p$ is list
896 of nodes, in reverse order, along a path from the @<root> to some other
897 node, and $c$ is the total cost of traversing this path. (Therefore @|(car
898 $p$)| is the destination node, and @|(car (last $p$))| is always the
899 @<root> itself.)
900
901 The function runs in $O(n^2)$ time, where $n$ is the number of nodes
902 reachable from the @<root>. Currently, it uses an algorithm due to Edsger
903 Dijkstra.
904 \end{describe}
905
906
907 \subsection{Other exported symbols}
908
909 \begin{describe}{sym}{int}
910 The symbol @|int| is exported by the @|sod-utilities| package, without
911 giving it any particular meaning. This is done because it's given
912 non-conflicting meanings by two different packages, and it's more
913 convenient for user code not to have to deal with an unnecessary symbol
914 conflict. Specifically, the @|sod| package wants to define it as a C type
915 specifier, see \descref{cls}{simple-c-type}; and @|optparse| wants to
916 define it as an option handler, see \descref{opt}{int}.
917 \end{describe}
918
919 %%%--------------------------------------------------------------------------
920 \section{Option parser} \label{sec:misc.optparse}
921
922 Most of these symbols are defined in the @|optparse| package.
923
924 \begin{describe}{var}{*program-name*}
925 \end{describe}
926
927 \begin{describe}{var}{*command-line*}
928 \end{describe}
929
930 \begin{describe}{fun}{set-command-line-arguments}
931 \end{describe}
932
933 \begin{describe}{fun}{moan @<format-string> \&rest @<format-args>}
934 \end{describe}
935
936 \begin{describe}{fun}{die @<format-string> \&rest @<format-args>}
937 \end{describe}
938
939 \begin{describe}{var}{*options*}
940 \end{describe}
941
942 \begin{describe}{cls}{option}
943 \end{describe}
944
945 \begin{describe}{fun}{optionp @<object> @> @<generalized-boolean>}
946 \end{describe}
947
948 \begin{describe}{fun}
949 {make-option \=@<long-name> @<short-name> \+\\
950 \&optional @<arg-name> \\
951 \&key :tag :negated-tag
952 :arg-optional-p :documentation \-
953 \nlret @<option>}
954 \end{describe}
955
956 \begin{describe*}
957 {\dhead{fun}{opt-short-name @<option> @> @<character-or-null>}
958 \dhead{fun}{setf (opt-short-name @<option>) @<character-or-null>}
959 \dhead{fun}{opt-long-name @<option> @> @<string-or-null>}
960 \dhead{fun}{setf (opt-long-name @<option>) @<string-or-null>}
961 \dhead{fun}{opt-tag @<option> @> @<tag>}
962 \dhead{fun}{setf (opt-tag @<option>) @<tag>}
963 \dhead{fun}{opt-negated-tag @<option> @> @<tag>}
964 \dhead{fun}{setf (opt-negated-tag @<option>) @<tag>}
965 \dhead{fun}{opt-arg-name @<option> @> @<string-or-null>}
966 \dhead{fun}{setf (opt-arg-name @<option>) @<string-or-null>}
967 \dhead{fun}{opt-arg-optional-p @<option> @> @<generalized-boolean>}
968 \dhead{fun}{setf (opt-arg-optional-p @<option>) @<generalized-boolean>}
969 \dhead{fun}{opt-documentation @<option> @> @<string-or-null>}
970 \dhead{fun}{setf (opt-documentation @<option>) @<string-or-null>}}
971 \end{describe*}
972
973 \begin{describe}{cls}{option-parser}
974 \end{describe}
975
976 \begin{describe}{fun}{option-parser-p @<object> @> @<generalized-boolean>}
977 \end{describe}
978
979 \begin{describe}{fun}
980 {make-option-parser \&key \=:args :options :non-option :numericp \+ \\
981 :negated-numeric-p long-only-p \-
982 \nlret @<option-parser>}
983 \end{describe}
984
985 \begin{describe*}
986 {\dhead{fun}{op-options @<option-parser> @> @<list>}
987 \dhead{fun}{setf (op-options @<option-parser>) @<list>}
988 \dhead{fun}{op-non-option @<option-parser> @> @<action>}
989 \dhead{fun}{setf (op-non-option @<option-parser>) @<action>}
990 \dhead{fun}{op-long-only-p @<option-parser> @> @<generalized-boolean>}
991 \dhead{fun}{setf (op-long-only-p @<option-parser>) @<generalized-boolean>}
992 \dhead{fun}{op-numeric-p @<option-parser> @> @<generalized-boolean>}
993 \dhead{fun}{setf (op-numeric-p @<option-parser>) @<generalized-boolean>}
994 \dhead{fun}{op-negated-numeric-p @<option-parser> @<generalized-boolean>}
995 \dhead{fun}{setf (op-negated-numeric-p @<option-parser>) @<generalized-boolean>}
996 \dhead{fun}{op-negated-p @<option-parser> @> @<generalized-boolean>}
997 \dhead{fun}{setf (op-negated-p @<option-parser>) @<generalized-boolean>}}
998 \end{describe*}
999
1000 \begin{describe}{cls}
1001 {option-parse-error (error simple-condition)
1002 \&key :format-control :format-arguments}
1003 \end{describe}
1004
1005 \begin{describe}{fun}{option-parse-error @<msg> \&optional @<args>}
1006 \end{describe}
1007
1008 \begin{describe}{fun}{option-parse-remainder @<option-parser>}
1009 \end{describe}
1010
1011 \begin{describe}{fun}{option-parse-return @<tag> \&optional @<argument>}
1012 \end{describe}
1013
1014 \begin{describe}{fun}{option-parse-next @<option-parser>}
1015 \end{describe}
1016
1017 \begin{describe}{mac}{option-parse-try @<form>^*}
1018 \end{describe}
1019
1020 \begin{describe}{mac}{with-unix-error-reporting () @<form>^*}
1021 \end{describe}
1022
1023 \begin{describe}{mac}
1024 {defopthandler @<name> (@<var> @[@<arg>@]) @<lambda-list> \\ \ind
1025 @[[ @<declaration>^* @! @<doc-string> @]] \\
1026 @<form>^*}
1027 \end{describe}
1028
1029 \begin{describe*}
1030 {\dhead{sym}{opthandler}
1031 \dhead{meth}{symbol,(eql 'opthandler)}
1032 {documentation (@<symbol> symbol)
1033 (@<doc-type> (eql 'opthandler))}
1034 \dhead{meth}{symbol,(eql 'opthandler)}
1035 {setf \=(documentation (@<symbol> symbol)
1036 (@<doc-type> (eql 'opthandler))) \\
1037 \>@<string>}}
1038 \end{describe*}
1039
1040 \begin{describe}{fun}
1041 {invoke-option-handler @<handler> @<locative> @<arg> @<arguments>}
1042 \end{describe}
1043
1044 \begin{describe}{opt}{set \&optional @<value>}
1045 \end{describe}
1046
1047 \begin{describe}{opt}{clear \&optional @<value>}
1048 \end{describe}
1049
1050 \begin{describe}{opt}{inc \&optional @<maximum> @<step>}
1051 \end{describe}
1052
1053 \begin{describe}{opt}{dec \&optional @<minimum> @<step>}
1054 \end{describe}
1055
1056 \begin{describe}{opt}{read}
1057 \end{describe}
1058
1059 \begin{describe}{opt}{int \&key :radix :min :max}
1060 \end{describe}
1061
1062 \begin{describe}{opt}{string}
1063 \end{describe}
1064
1065 \begin{describe}{opt}{keyword \&optional @<valid>}
1066 \end{describe}
1067
1068 \begin{describe}{opt}{list \&optional @<handler> \&rest @<handler-args>}
1069 \end{describe}
1070
1071 \begin{describe}{mac}
1072 {defoptmacro @<name> @<lambda-list> \\ \ind
1073 @[[ @<declaration>^* @! @<doc-string> @]] \\
1074 @<form>^*}
1075 \end{describe}
1076
1077 \begin{describe*}
1078 {\dhead{sym}{optmacro}
1079 \dhead{meth}{symbol,(eql 'optmacro)}
1080 {documentation (@<symbol> symbol)
1081 (@<doc-type> (eql 'optmacro))}
1082 \dhead{meth}{symbol,(eql 'optmacro)}
1083 {setf \=(documentation (@<symbol> symbol)
1084 (@<doc-type> (eql 'optmacro))) \\
1085 \>@<string>}}
1086 \end{describe*}
1087
1088 \begin{describe}{fun}{parse-option-form @<form>}
1089 \end{describe}
1090
1091 \begin{describe}{mac}
1092 {options @{ \=@<string> @! \+ \\
1093 @<option-macro> @! (@<option-macro> @<macro-arg>^*) @! \\
1094 (@[[ \=@<character> @! (:short-name @<character>) @! \+ \\
1095 @<string>^* @! @<symbol> @! @<rational> @!
1096 (:long-name @<string>) @! \\
1097 (@<string> @<format-arg>^+) @!
1098 (:doc @<string> @<format-arg>^*) @! \\
1099 (:arg @<arg-name>) @! (:opt-arg @<arg-name>) @! \\
1100 @<keyword> @! (:tag @<tag>) @!
1101 (:negated-tag @<tag>) @! \\
1102 @{ (@<handler> @<var> @<handler-arg>^*) @}^*
1103 @]]) @}^*}
1104 \end{describe}
1105
1106 \begin{describe}{fun}
1107 {simple-usage @<option-list> \&optional @<mandatory-args> @> @<list>}
1108 \end{describe}
1109
1110 \begin{describe}{fun}{show-usage @<prog> @<usage> \&optional @<stream>}
1111 \end{describe}
1112
1113 \begin{describe}{fun}
1114 {show-help @<prog> @<usage> @<option-list> \&optional @<stream>}
1115 \end{describe}
1116
1117 \begin{describe}{fun}{sanity-check-option-list @<option-list>}
1118 \end{describe}
1119
1120 \begin{describe*}
1121 {\dhead{var}{*help*}
1122 \dhead{var}{*version*}
1123 \dhead{var}{*usage*}}
1124 \end{describe*}
1125
1126 \begin{describe}{fun}{do-usage \&optional @<stream>}
1127 \end{describe}
1128
1129 \begin{describe}{fun}{die-usage}
1130 \end{describe}
1131
1132 \begin{describe}{optmac}
1133 {help-options \&key :short-help :short-version :short-usage}
1134 \end{describe}
1135
1136 \begin{describe}{fun}
1137 {define-program \&key \=:program-name \+ \\
1138 :help :version :usage :full-usage \\
1139 :options}
1140 \end{describe}
1141
1142 \begin{describe}{mac}
1143 {do-options (@[[ :parser @<option-parser> @]]) \\ \ind
1144 @{ (@{ @<case> @! (@<case>^*)@} (@[@[@<opt-var>@] @<arg-var>@])
1145 @<form>^*) @}^*}
1146 \end{describe}
1147
1148 \begin{describe}{fun}{sod-frontend:augment-options @<options-list>}
1149 \end{describe}
1150
1151 %%%--------------------------------------------------------------------------
1152 \section{Property sets} \label{sec:misc.pset}
1153
1154 \begin{describe}{fun}{property-key @<name> @> @<keyword>}
1155 \end{describe}
1156
1157 \begin{describe}{gf}{decode-property @<raw-value> @> @<type> @<value>}
1158 \end{describe}
1159
1160 \begin{describe}{cls}{property}
1161 \end{describe}
1162
1163 \begin{describe}{fun}{propertyp @<object> @> @<generalized-boolean>}
1164 \end{describe}
1165
1166 \begin{describe}{fun}
1167 {make-property @<name> @<raw-value> \&key :type :location :seenp}
1168 \end{describe}
1169
1170 \begin{describe*}
1171 {\dhead{fun}{p-name @<property> @> @<name>}
1172 \dhead{meth}{property}{file-location (@<property> property) @> @<floc>}
1173 \dhead{fun}{p-value @<property> @> @<value>}
1174 \dhead{fun}{p-type @<property> @> @<type>}
1175 \dhead{fun}{p-key @<property> @> @<symbol>}
1176 \dhead{fun}{p-seenp @<property> @> @<boolean>}
1177 \dhead{fun}{setf (p-seenp @<property>) @<boolean>}}
1178 \end{describe*}
1179
1180 \begin{describe}{gf}
1181 {coerce-property-value @<value> @<type> @<wanted> @> @<coerced-value>}
1182 \end{describe}
1183
1184 \begin{describe}{cls}{pset}
1185 \end{describe}
1186
1187 \begin{describe}{fun}{psetp @<object> @> @<generalized-boolean>}
1188 \end{describe}
1189
1190 \begin{describe}{fun}{make-pset @> @<pset>}
1191 \end{describe}
1192
1193 \begin{describe}{fun}{pset-get @<pset> @<key> @> @<property-or-nil>}
1194 \end{describe}
1195
1196 \begin{describe}{fun}{pset-store @<pset> @<property> @> @<property>}
1197 \end{describe}
1198
1199 \begin{describe}{fun}{pset-map @<func> @<pset>}
1200 \end{describe}
1201
1202 \begin{describe}{mac}
1203 {with-pset-iterator (@<iter> @<pset>) @<declaration>^* @<form>^*}
1204 \end{describe}
1205
1206 \begin{describe}{fun}
1207 {store-property @<pset> @<name> @<value> \&key :type :location
1208 @> @<property>}
1209 \end{describe}
1210
1211 \begin{describe}{fun}
1212 {get-property @<pset> @<name> @<type> \&optional @<default>
1213 @> @<value> @<floc-or-nil>}
1214 \end{describe}
1215
1216 \begin{describe}{fun}
1217 {add-property @<pset> @<name> @<value> \&key :type :location
1218 @> @<property>}
1219 \end{describe}
1220
1221 \begin{describe}{fun}{make-property-set \&rest @<plist> @> @<pset>}
1222 \end{describe}
1223
1224 \begin{describe}{gf}{property-set @<thing> @> @<pset>}
1225 \end{describe}
1226
1227 \begin{describe}{fun}{check-unused-properties @<pset>}
1228 \end{describe}
1229
1230 \begin{describe}{mac}
1231 {default-slot-from-property
1232 (@<instance> @<slot> @[@<slot-names>@]) \\ \ind\ind
1233 (@<pset> @<property> @<type> @[@<prop-var> @<convert-form>^*@]) \- \\
1234 @<declaration>^* \\
1235 @<default-form>^*}
1236 \end{describe}
1237
1238 \begin{describe}{fun}
1239 {parse-property @<scanner> @<pset>
1240 @> @<result> @<success-flag> @<consumed-flag>}
1241 \end{describe}
1242
1243 \begin{describe}{fun}
1244 {parse-property-set @<scanner>
1245 @> @<result> @<success-flag> @<consumed-flag>}
1246 \end{describe}
1247
1248 %%%--------------------------------------------------------------------------
1249 \section{Miscellaneous translator features} \label{sec:misc.misc}
1250
1251 \begin{describe}{var}{*sod-version*}
1252 \end{describe}
1253
1254 \begin{describe}{var}{*debugout-pathname*}
1255 \end{describe}
1256
1257 \begin{describe}{fun}
1258 {test-module @<path> \&key :reason :clear :backtrace @> @<status>}
1259 \end{describe}
1260
1261 \begin{describe}{fun}
1262 {test-parse-c-type @<string>
1263 @> t @<c-type> @<kernel> @<string> @! nil @<indicator>}
1264 \end{describe}
1265
1266 \begin{describe}{fun}
1267 {test-parse-pset @<string>
1268 @> t @<pset> @! nil @<indicator>}
1269 \end{describe}
1270
1271 \begin{describe}{mac}
1272 {test-parser (@<scanner> \&key :backtrace) @<parser> @<input>
1273 @> @<result> @<status> @<remainder>}
1274 \end{describe}
1275
1276 \begin{describe}{fun}{exercise}
1277 \end{describe}
1278
1279 \begin{describe}{fun}{sod-frontend:main}
1280 \end{describe}
1281
1282 %%%----- That's all, folks --------------------------------------------------
1283
1284 %%% Local variables:
1285 %%% mode: LaTeX
1286 %%% TeX-master: "sod.tex"
1287 %%% TeX-PDF-mode: t
1288 %%% End: