Document DUMP's &rest argument.
[clon.git] / doc / user.texi
bloba9217a09cc77afef5939234508ddfac17a25f70f
1 \input texinfo
3 @c user.texi --- User manual
5 @c Copyright (C) 2010, 2011, 2012 Didier Verna.
7 @c Author:     Didier Verna <didier@lrde.epita.fr>
8 @c Maintainer: Didier Verna <didier@lrde.epita.fr>
10 @c This file is part of Clon.
12 @c Permission to use, copy, modify, and distribute this software for any
13 @c purpose with or without fee is hereby granted, provided that the above
14 @c copyright notice and this permission notice appear in all copies.
16 @c THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
17 @c WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
18 @c MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
19 @c ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 @c WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
21 @c ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
22 @c OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 @c Commentary:
27 @c Contents management by FCM version 0.1.
30 @c ====================================================================
31 @c Header
32 @c ====================================================================
33 @c %**start of header
34 @setfilename clon-user.info
35 @settitle The Clon User Manual
36 @afourpaper
37 @documentencoding ISO-8859-1
38 @c %**end of header
42 @c ====================================================================
43 @c Settings
44 @c ====================================================================
45 @set VERSION 1.0 beta 22 "Michael Brecker"
46 @set COPYRIGHT_DATE 2010, 2011, 2012
47 @setchapternewpage odd
48 @setcontentsaftertitlepage
49 @documentdescription
50 The Clon User Manual for version @value{VERSION}.
51 @end documentdescription
55 @c ====================================================================
56 @c New Commands
57 @c ====================================================================
59 @macro clon
60 @t{Clon}
61 @end macro
63 @macro cl
64 Common Lisp
65 @end macro
67 @macro tty
68 @t{tty}
69 @end macro
71 @macro etc
72 @i{etc.}
73 @end macro
75 @macro eg
76 @i{e.g.}
77 @end macro
79 @macro ie
80 @i{i.e.}
81 @end macro
83 @macro perse
84 @i{per-se}
85 @end macro
87 @macro cmdline
88 command-line
89 @end macro
91 @macro CmdLine
92 Command-Line
93 @end macro
95 @macro bioption{name}
96 @option{--clon-\name\}
97 @end macro
100 @c --------------------------------
101 @c Manuals cross-referencing macros
102 @c --------------------------------
103 @c The following 3 macros are here to circumvent the info filenames
104 @c changes, when referencing the end-user manual:
106 @macro pxenduserref{node}
107 @ifinfo
108 @pxref{\node\, , , clon-enduser, The Clon End-User Manual}
109 @end ifinfo
110 @ifnotinfo
111 @pxref{\node\, , , enduser, The Clon End-User Manual}
112 @end ifnotinfo
113 @end macro
115 @macro xenduserref{node}
116 @ifinfo
117 @xref{\node\, , , clon-enduser, The Clon End-User Manual}
118 @end ifinfo
119 @ifnotinfo
120 @xref{\node\, , , enduser, The Clon End-User Manual}
121 @end ifnotinfo
122 @end macro
124 @macro enduserref{node}
125 @ifinfo
126 @ref{\node\, , , clon-enduser, The Clon End-User Manual}
127 @end ifinfo
128 @ifnotinfo
129 @ref{\node\, , , enduser, The Clon End-User Manual}
130 @end ifnotinfo
131 @end macro
134 @c ---------------
135 @c Indexing macros
136 @c ---------------
138 @c Concept index
139 @c -------------
141 @c Built-in options
142 @macro bioindex{opt}
143 @cindex @t{--clon-\opt\}
144 @cindex Built-In Options, @t{--clon-\opt\}
145 @cindex Options, built-in, @t{--clon-\opt\}
146 @end macro
148 @c Common option properties
149 @macro copindex{prop}
150 @cindex Options, common properties, @t{\prop\}
151 @cindex Common Option Properties, @t{\prop\}
152 @end macro
154 @c Options
155 @c #### NOTE: not an alias because of argument syntax.
156 @macro oindex{name,class}
157 @cindex \name\ (@t{\class\})
158 @cindex Options, \name\ (@t{\class\})
159 @ocindex{\class\}
160 @end macro
162 @c Valued options
163 @macro voindex{name,class}
164 @cindex \name\ (@t{\class\})
165 @cindex Valued Options, \name\ (@t{\class\})
166 @cindex Options, valued, \name\ (@t{\class\})
167 @ocindex{\class\}
168 @end macro
170 @c Common valued option properties
171 @macro cvopindex{prop}
172 @cindex Valued Options, common properties, @t{\prop\}
173 @cindex Common Valued Option Properties, @t{\prop\}
174 @cindex Options, valued, common properties, @t{\prop\}
175 @end macro
177 @c Valued option properties
178 @macro vopindex{name,class,prop}
179 @cindex \name\ (@t{\class\}), properties, @t{\prop\}
180 @cindex Valued Options, \name\ (@t{\class\}), properties, @t{\prop\}
181 @cindex Options, valued, \name\ (@t{\class\}), properties, @t{\prop\}
182 @end macro
184 @c Configuration options
185 @macro coindex{name}
186 @vindex com.dvlsoft.clon.configuration
187 @cindex Configuration Option, @t{:\name\}
188 @cindex @t{:\name\}
189 @end macro
192 @c Functions index
193 @c ---------------
195 @c Function options
196 @macro foindex{func,opt}
197 @findex \func\@r{, options, }\opt\
198 @end macro
200 @c Function items
201 @macro fiindex{func,item}
202 @findex \func\@r{, items, }\item\
203 @end macro
205 @c Function keys
206 @macro fkindex{func,key}
207 @findex \func\@r{, keys, }\key\
208 @end macro
210 @c Function initargs
211 @macro fiaindex{func,arg}
212 @findex \func\@r{, initargs, }\arg\
213 @end macro
215 @c Generic functions sub-index
216 @macro gfsubindex{func}
217 @findex @r{Generic Functions, }\func\
218 @end macro
220 @c Generic functions
221 @macro gfindex{func}
222 @findex \func\
223 @gfsubindex{\func\}
224 @end macro
226 @c Generic function methods
227 @macro gfmindex{func,method}
228 @findex \func\@r{, methods, }\method\
229 @findex @r{Generic Functions, }\func\@r{, methods, }\method\
230 @end macro
232 @c #### FIXME: I need this because when using @defun, the function is
233 @c referenced directly but not under the Constructors sub-index. This
234 @c sucks because what I would like is the ability to define my own
235 @c @defXXX macros, which apparently I can't. Besides, doing this
236 @c produces 2 separate index entries, instead of only one with two pagerefs.
237 @c This problem stands for @gfsubindex (see above), @rfsubindex (see
238 @c below) and @ecsubindex (see below) as well.
239 @c Constructor functions sub-index
240 @macro cfsubindex{func}
241 @findex @r{Constructors, }\func\
242 @end macro
244 @c Constructor functions
245 @macro cfindex{func}
246 @findex \func\
247 @cfsubindex{\func\}
248 @end macro
250 @c Constructor function initargs
251 @macro cfiaindex{func,arg}
252 @fiaindex{\func\, \arg\}
253 @findex @r{Constructors, }\func\@r{, initargs, }\arg\
254 @end macro
256 @c Reader functions subindex
257 @macro rfsubindex{func}
258 @findex @r{Readers, }\func\
259 @end macro
261 @c Reader functions
262 @macro rfindex{func}
263 @findex \func\
264 @rfsubindex{\func\}
265 @end macro
268 @c Variables index
269 @c ---------------
271 @c Environment variables
272 @macro evindex{var}
273 @vindex \var\
274 @vindex @r{Environment, }\var\
275 @end macro
277 @c Built-in environment variables
278 @macro bievindex{var}
279 @evindex{CLON_\var\}
280 @end macro
283 @c Data Types index
284 @c ----------------
286 @c Classes
287 @macro clsindex{cls}
288 @tpindex \cls\
289 @tpindex @r{Classes, }\cls\
290 @end macro
292 @c Class slots
293 @macro clssindex{cls,slot}
294 @tpindex \cls\@r{, slots, }\slot\
295 @tpindex @r{Classes, }\cls\@r{, slots, }\slot\
296 @end macro
298 @c Class initargs
299 @macro clsiaindex{cls,arg}
300 @tpindex \cls\@r{, initargs, }\arg\
301 @tpindex @r{Classes, }\cls\@r{, initargs, }\arg\
302 @end macro
304 @c Option classes
305 @macro ocindex{cls}
306 @clsindex{\cls\}
307 @tpindex @r{Option Classes, }\cls\
308 @end macro
310 @c Error conditions subindex
311 @macro ecsubindex{cond}
312 @tpindex @r{Error Conditions, }\cond\
313 @end macro
315 @c Error conditions
316 @macro ecindex{cond}
317 @tpindex \cond\
318 @ecsubindex{\cond\}
319 @end macro
321 @c Error condition slots
322 @macro ecsindex{cond,slot}
323 @tpindex \cond\@r{, slots, }\slot\
324 @tpindex @r{Error Conditions, }\cond\@r{, slots, }\slot\
325 @end macro
327 @c Packages
328 @macro pkgindex{name}
329 @tpindex \name\
330 @tpindex @r{Packages, }\name\
331 @end macro
333 @c Systems
334 @macro sysindex{name}
335 @tpindex \name\
336 @tpindex @r{Systems, }\name\
337 @end macro
341 @c ====================================================================
342 @c Info Category and Directory
343 @c ====================================================================
344 @dircategory Common Lisp
345 @direntry
346 * Clon User: (clon-user).               The Clon User Manual.
347 @end direntry
351 @c ====================================================================
352 @c Copying
353 @c ====================================================================
354 @copying
355 @quotation
356 Copyright @copyright{} @value{COPYRIGHT_DATE} Didier Verna
358 Permission is granted to make and distribute verbatim copies of this
359 manual provided the copyright notice and this permission notice are
360 preserved on all copies.
362 @ignore
363 Permission is granted to process this file through TeX and print the
364 results, provided the printed document carries a copying permission
365 notice identical to this one except for the removal of this paragraph
366 (this paragraph not being relevant to the printed manual).
368 @end ignore
369 Permission is granted to copy and distribute modified versions of this
370 manual under the conditions for verbatim copying, provided also that the
371 section entitled ``Copying'' is included exactly as in the original.
373 Permission is granted to copy and distribute translations of this manual
374 into another language, under the above conditions for modified versions,
375 except that this permission notice may be translated as well.
376 @end quotation
377 @end copying
381 @c ====================================================================
382 @c Title Page
383 @c ====================================================================
384 @titlepage
385 @title The Clon User Manual
386 @subtitle The @CmdLine{} Options Nuker, Version @value{VERSION}
387 @vskip 2cm
388 @image{splash,16cm}
389 @author Didier Verna <@email{didier@@lrde.epita.fr}>
390 @page
391 @vskip 0pt plus 1filll
392 @insertcopying
394 @hfill Cover art by Alexis Angelidis.
395 @end titlepage
399 @c ====================================================================
400 @c Table of Contents
401 @c ====================================================================
402 @contents
406 @c ====================================================================
407 @c Master Menu
408 @c ====================================================================
409 @ifnottex
410 @node Top, Copying, (dir), (dir)
411 @top The Clon User Manual
413 This is the @clon{} User Manual for @clon{} version @value{VERSION}:
414 it explains how to use @clon{} in your application.
416 @menu
417 * Copying::                 The BSD license
418 * Introduction::            What Clon is all about
419 * Installation::            Library, documentation and sample code
420 * Quick Start::             For the brave and the impatient
421 * Using Clon::              Clonificating your application
422 * Extending Clon::          Creating your own option types
423 * Advanced Usage::          Things rarely needed
424 * Conclusion::              That's all folks
425 * Technical Notes::         Configuration, platforms and portability
426 * API Quick Reference::     The Complete protocols
427 * Indexes::                 Concept, Function and Variable
428 * Acknowledgments::         Hall of Pride
429 @end menu
431 @insertcopying
432 @end ifnottex
436 @c ====================================================================
437 @c Copying
438 @c ====================================================================
439 @node Copying, Introduction, Top, Top
440 @unnumbered Copying
442 @quotation
443 Permission to use, copy, modify, and distribute this software for any
444 purpose with or without fee is hereby granted, provided that the above
445 copyright notice and this permission notice appear in all copies.
447 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
448 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
449 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
450 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
451 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
452 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
453 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
454 @end quotation
458 @c ====================================================================
459 @c Introduction
460 @c ====================================================================
461 @node Introduction, Installation, Copying, Top
462 @chapter Introduction
464 @clon{} is a library for managing @cmdline{} options in standalone @cl{}
465 applications. It provides a unified option syntax with both short and
466 long names, automatic completion of partial names and automatic
467 retrieval/conversion of option arguments from the @cmdline{}, associated
468 environment variables, fallback or default values. @clon{} comes with a
469 set of extensible option types (switches, paths, strings @etc{}).
470 @clon{} also provides automatic generation and formatting of help
471 strings, with support for highlighting on @tty{}'s through ISO/IEC 6429
472 SGR. This formatting is customizable through @emph{themes}.
474 Depending on the target audience, @clon{} stands for either ``The
475 @CmdLine{} Options Nuker'' or ``The @cl{} Options Nuker''. @clon{} also
476 has a recursive acronym: ``@clon{} Likes Options Nuking'', and a reverse
477 one: ``Never Omit to Link with @clon{}''. Other possible expansions of
478 the acronym are still being investigated.
480 This manual is for the @clon{} @emph{user}, that is, the developer of a
481 @cl{} application who wants to use @clon{} for @cmdline{} option
482 management@footnote{An application using @clon{} for its @cmdline{}
483 option management is said to be @emph{clonified}. It is also possible to
484 say @emph{clonfiscated}. However, we advise against using
485 @emph{clonistified}. The term @emph{clonificated} is also considered bad
486 style, and the use of @emph{clonificationated} is strictly prohibited.}.
487 As opposed to the user of the @emph{library}, the user of an
488 @emph{application} powered by @clon{} is called an @emph{end-user}.
489 @clon{} provides both a user manual (this one) and an end-user manual
490 (@pxenduserref{Top}). Everybody should read the end-user manual first.
492 @ref{Quick Start} provides a very short example in order to give an
493 overview of what's coming next. @ref{Using Clon} explains in detail how
494 to clonify your application, and @ref{Extending Clon} describe how to
495 extend @clon{} with your own option types.
499 @c ====================================================================
500 @c Installation
501 @c ====================================================================
502 @node Installation, Quick Start, Introduction, Top
503 @chapter Installation
504 @clon{} currently works on Unix (including MacOS X) and Windows (Cygwin
505 or MinGW) with SBCL (> 1.0.56), CMUCL (> 20b), CCL, ECL, CLISP, ABCL (>
506 1.1.0), Allegro (both standard and modern) and LispWorks. @clon{} is
507 provided as an ASDF 2 system, but has no mandatory dependency. CFFI may
508 optionally be used with CLISP, Allegro and LispWorks. @xref{Supported
509 Platforms}, for more information.
511 In order to install and load the bare Lisp library, unpack it somewhere
512 in the ASDF 2 source registry and type this at the REPL:
513 @verbatim
514 (asdf:load-system :com.dvlsoft.clon)
515 @end verbatim
516 If you are using SBCL, you may want to make sure that the @code{CC}
517 environment variable is set to your favorite C compiler in your init
518 file. Otherwise, @clon{} will run in restricted mode (@pxref{Technical
519 Notes}). For instance, put this in your @file{.sbclrc}:
520 @verbatim
521 (require :sb-posix)
522 (sb-posix:setenv "CC" "gcc" 1)
523 @end verbatim
525 In addition to the library itself, the Clon distribution offers
526 documentation in the form of 3 different manuals, some data files like
527 sample themes (@pxenduserref{Theme Creation}), and a couple of
528 demonstration programs. If you want to benefit from all those wonders,
529 some bits of manual installation are needed. After unpacking somewhere
530 in the ASDF 2 source registry, please perform the following steps, in
531 order.
533 @enumerate
534 @item
535 Edit @file{Makefile.cnf} to your specific needs.
537 @item
538 Type @command{make} to compile the documentation and the demo programs
539 (end-user manual, user manual and possibly reference manual). By
540 default, the documentation is built in info, PDF and HTML formats. If
541 you want other formats (DVI and PostScript are available), type
542 @command{make all-formats}. You can also type individually @command{make
543 dvi} and/or @command{make ps} in order to get the corresponding format.
545 @item
546 As documented in @file{Makefile.cnf}, the reference manual is only
547 generated if you have SBCL and the Declt library at hand (see
548 @uref{http://www.lrde.epita.fr/~didier/software/lisp/misc.php#declt}).
550 @item
551 Type @command{make install} to install both the documentation and the
552 data files. If you have compiled the documentation in DVI and PostScript
553 format, those will be installed as well. The same goes for the reference
554 manual. The demo programs are not installed anywhere.
555 @end enumerate
557 Type @command{make uninstall} to uninstall the library.
561 @c ====================================================================
562 @c Quick Start
563 @c ====================================================================
564 @node Quick Start, Using Clon, Installation, Top
565 @chapter Quick Start
566 In this chapter, we assume that you have properly installed @clon{}
567 (@pxref{Technical Notes}), and we build a very short program to get you
568 started. Let's call it @file{quickstart.lisp}.
570 @menu
571 * Full Source::         The complete source code
572 * Explanation::         Step-by-step code walking
573 @end menu
576 @c -----------
577 @c Full Source
578 @c -----------
579 @node Full Source, Explanation, Quick Start, Quick Start
580 @section Full Source
581 For cut'n paste convenience, the complete source code is given below.
582 For a slightly longer example, have a look at the demonstration program
583 called @file{simple} in the distribution.
585 @cartouche
586 @verbatim
587 (in-package :cl-user)
589 (require :asdf)
590 (asdf:load-system :com.dvlsoft.clon)
591 (use-package :com.dvlsoft.clon)
593 (defsynopsis (:postfix "FILES...")
594   (text :contents "A very short program.")
595   (group (:header "Immediate exit options:")
596     (flag :short-name "h" :long-name "help"
597       :description "Print this help and exit.")
598     (flag :short-name "v" :long-name "version"
599           :description "Print version number and exit.")))
601 (defun main ()
602   "Entry point for our standalone application."
603   (make-context)
604   (when (getopt :short-name "h")
605     (help)
606     (exit))
607   (do-cmdline-options (option name value source)
608     (print (list option name value source)))
609   (terpri)
610   (exit))
612 (dump "quickstart" main)
613 @end verbatim
614 @end cartouche
617 @c -----------
618 @c Explanation
619 @c -----------
620 @node Explanation, , Full Source, Quick Start
621 @section Explanation
622 Let's examine this program step-by-step now.
624 @pkgindex{com.dvlsoft.clon}@c
625 @sysindex{com.dvlsoft.clon}@c
626 First, we put ourselves in the @cl{} user package, and load @clon{} from
627 its ASDF system @samp{com.dvlsoft.clon}. Next, we use the @clon{}
628 package, also named @samp{com.dvlsoft.clon}.
630 @cartouche
631 @verbatim
632 (in-package :cl-user)
634 (require :asdf)
635 (asdf:load-system :com.dvlsoft.clon)
636 (use-package :com.dvlsoft.clon)
637 @end verbatim
638 @end cartouche
640 In fact, using the @clon{} package directly is done here for simplicity,
641 but is not recommended. In case you find the package name too long to
642 prefix every symbol with, @clon{} provides a utility function that
643 allows you to add (and use) a shorter nickname instead (the
644 demonstration programs in the distribution show how to use it):
646 @cindex Package, nicknames
647 @defun nickname-package &optional NICKNAME
648 Add NICKNAME (:CLON by default) to the :COM.DVLSOFT.CLON package.
649 @end defun
651 @cindex Synopsis
652 @findex defsynopsis
653 @cindex Postfix
654 @cindex Text, in synopsis
655 @cindex Options, in synopsis
656 @cindex Groups, in synopsis
657 @cindex Help String
658 The next thing you want to do is to create a set of options, groups or
659 texts that your application will recognize and/or display in its help
660 string. The structure of your @cmdline{} is known to @clon{} as the
661 @dfn{synopsis}. In order to create it, use the macro @code{defsynopsis}.
663 @foindex{defsynopsis,:postfix}
664 @fiindex{defsynopsis,text}
665 @fiindex{defsynopsis,options}
666 @fiindex{defsynopsis,group}
667 @cartouche
668 @verbatim
669 (defsynopsis (:postfix "FILES...")
670   (text :contents "A very short program.")
671   (group (:header "Immediate exit options:")
672     (flag :short-name "h" :long-name "help"
673       :description "Print this help and exit.")
674     (flag :short-name "v" :long-name "version"
675           :description "Print version number and exit.")))
676 @end verbatim
677 @end cartouche
679 Note that the synopsis has a double role: it not only serves to define
680 the options recognized by your application, but also the order in which
681 every element appears in the help string. In that particular example, we
682 define a line of text and a group with a header and two flags.
684 @cindex Context
685 @cfindex{make-context}
686 Now, we are going to define a function @code{main} for our standalone
687 application. The first thing that we need to do is create a
688 @dfn{context}. A context is an object that @clon{} uses to store various
689 things, including some state related to the parsing of the @cmdline{}.
690 You create a context with the function @code{make-context}.
692 @cartouche
693 @verbatim
694 (defun main ()
695   "Entry point for our standalone application."
696   (make-context)
697 @end verbatim
698 @end cartouche
700 @cindex Options Retrieval, explicit
701 @cindex Retrieval, of options, explicit
702 @findex getopt
703 @cindex Help String, display
704 @findex help
705 At that point, @clon{} is ready to retrieve the options you want from
706 the @cmdline{}. Let's first see if the user has called the option
707 @option{-h}, and give him the help string. Option retrieval is done with
708 the function @code{getopt}, and automatic help string output with the
709 function @code{help}. Note that what we do here is @emph{not} process
710 the @cmdline{} in sequence, but look directly for a specific option by
711 name (this retrieval method is said to be @dfn{explicit}).
713 @fkindex{getopt,:short-name}
714 @cartouche
715 @verbatim
716   (when (getopt :short-name "h")
717     (help)
718     (exit))
719 @end verbatim
720 @end cartouche
722 @findex exit
723 The @code{exit} function is a wrapper around an
724 implementation-dependent way to exit (shall I say quit?) the @cl{}
725 environment, hence the program. It takes an optional argument that
726 stands for the exit status.
728 @cindex Options Retrieval, sequential
729 @cindex Retrieval, of options, sequential
730 @findex do-cmdline-options
731 And now, we are going to retrieve the other options and simply print
732 them. This time however, we process the @cmdline{} sequentially (so this
733 retrieval method is said to be @dfn{sequential}). This is done with the
734 @code{do-cmdline-options} macro. We also close the @code{main} function.
736 @cartouche
737 @verbatim
738   (do-cmdline-options (option name value source)
739     (print (list option name value source)))
740   (terpri)
741   (exit))
742 @end verbatim
743 @end cartouche
745 Finally, time to save the Lisp image.
747 @cindex Dumping
748 @findex dump
749 @cartouche
750 @verbatim
751 (dump "quickstart" main)
752 @end verbatim
753 @end cartouche
755 The first argument to @code{dump} is the name of the executable to
756 produce, and the second argument is the name of the function to call
757 automatically at startup. In fact, @code{dump} also accepts a
758 @code{&rest} argument that just be passed on to the underlying
759 (implementation-specific) dumping facility.
761 In order to get a standalone executable from this program, all you need
762 to do now is to type @samp{CC=gcc sbcl --script quickstart.lisp}. Note
763 that the actual way of dumping executables is compiler-dependent. For
764 more information on the proper way to do it and on the compilers
765 currently supported, see @ref{Dumping Executables}.
767 Note also that it is possible to use @clon{} without actually dumping a
768 standalone executable (@pxref{Not Dumping Executables}).
772 @c ====================================================================
773 @c Using Clon
774 @c ====================================================================
775 @node Using Clon, Extending Clon, Quick Start, Top
776 @chapter Using Clon
778 Using @clon{} in your application is a two stages process. In phase 1,
779 you create a @dfn{synopsis}, which is a description of your
780 application's @cmdline{} and a @dfn{context}, which describes this
781 specific execution of the program. In phase 2, you retrieve the option
782 values and possibly display help strings. Phase 1 is called the
783 @dfn{initialization phase}, while phase 2 is called the @dfn{runtime
784 phase}.
786 @menu
787 * Synopsis Definition:: Describing your command-line
788 * Context Creation::    Instantiating your command-line
789 * Integrity Checks::    Verifying the Clon semantics
790 * Option Retrieval::    Getting the options values
791 * Help::                Generating the help string
792 @end menu
795 @c -------------------
796 @c Synopsis Definition
797 @c -------------------
798 @node Synopsis Definition, Context Creation, Using Clon, Using Clon
799 @section Synopsis Definition
801 @cindex Initialization Phase
802 @cindex Phase, initialization
803 @cindex Synopsis
804 @cindex Help String
805 Step one of the @clon{} initialization phase consists in defining a
806 @dfn{synopsis}. A synopsis is essentially a description of your
807 application's @cmdline{}: it describes what are the available options,
808 whether your application has a postfix @etc{} The synopsis, however,
809 plays a second role: it also describes the contents of your
810 application's help string. When you create a synopsis, you describe the
811 @cmdline{} and the help string at the same time.
813 @menu
814 * Synopsis Items::              Defsynopsis and its contents
815 * Built-In Option Types::       The exhaustive list
816 * Advanced Synopsis Creation::  The non-declarative way
817 @end menu
819 @node Synopsis Items, Built-In Option Types, Synopsis Definition, Synopsis Definition
820 @subsection Synopsis Items
821 Look again at the synopsis definition provided in @ref{Quick Start}.
823 @cartouche
824 @verbatim
825 (defsynopsis (:postfix "FILES...")
826   (text :contents "A very short program.")
827   (group (:header "Immediate exit options:")
828     (flag :short-name "h" :long-name "help"
829           :description "Print this help and exit.")
830     (flag :short-name "v" :long-name "version"
831           :description "Print version number and exit.")))
832 @end verbatim
833 @end cartouche
835 You define a synopsis with the @code{defsynopsis} macro.
837 @defmac defsynopsis ([OPTIONS@dots{}]) ITEMS@dots{}
838 Define a new synopsis and return it. @var{OPTIONS} are key/value pairs.
839 @var{ITEMS} are text, group or option descriptions.
841 The following @var{OPTIONS} are currently available.
842 @table @t
843 @item :postfix
844 @cindex Postfix
845 @foindex{defsynopsis,:postfix}@c
846 @cindex Command-Line, remainder
847 @cindex Remainder, of command-line
848 A string which will appear at the end of the synopsis line in the help
849 string. When you provide a postfix, you also implicitely tell @clon{}
850 that your application accepts non-option arguments at the end of the
851 @cmdline{} (this is called the @dfn{remainder} of the @cmdline{}). See
852 @enduserref{Option Separator} for more information on the behavior of
853 @clon{} with respect to postfixes. Also, see @ref{Command-Line
854 Remainder} on how to access the @cmdline{} remainder.
855 @end table
856 @end defmac
858 We now examine the syntax for each possible @var{ITEM}.
859 @menu
860 * Text::        Adding arbitrary text
861 * Options::     Adding options
862 * Groups::      Adding groups
863 @end menu
865 @node Text, Options, Synopsis Items, Synopsis Items
866 @subsubsection Text
867 @cindex Text
868 @cindex Text, in synopsis
869 @fiindex{defsynopsis,text}
870 In order to add arbitrary text to your help string, use the following
871 form:
873 @noindent
874 @t{(text} [@var{OPTIONS@dots{}}]@t{)}
876 @var{OPTIONS} are key/value pairs. The following @var{OPTIONS} are
877 currently available.
878 @table @t
879 @item :contents
880 @cindex Text, contents
881 The actual text string. Try to make proper sentences when adding
882 arbitrary text. You can use explicit newline characters in your text if
883 you really want to go next line, but in general, you should not worry
884 about the formatting because the themes are here to do so. In
885 particular, don't finish your text with a newline. This would break
886 potential theme specifications.
887 @item :hidden
888 @cindex Hidden Text
889 @cindex Text, hidden
890 @cindex Help String
891 When non-@code{nil}, the text won't appear in the help string. Hidden
892 texts can still be displayed individually though (@pxref{Help}).
893 @end table
895 @node Options, Groups, Text, Synopsis Items
896 @subsubsection Options
897 @cindex Options
898 @cindex Options, in synopsis
899 @fiindex{defsynopsis,options}
900 In order to add an option to your help string, you must provide a list
901 beginning with the option type and followed by key/value pairs
902 describing the option's properties. For instance, to add a flag with a
903 short name and a description, you could do this:
905 @verbatim
906 (flag :short-name "h" :description "Print this help and exit.")
907 @end verbatim
909 Option properties vary depending on the option type. The exact list of
910 available option types, and the corresponding properties are described
911 in @ref{Built-In Option Types}.
913 @node Groups, , Options, Synopsis Items
914 @subsubsection Groups
915 @cindex Groups
916 @cindex Groups, in synopsis
917 @fiindex{defsynopsis,group}
918 In order to add a group to your help string, use the following form:
920 @noindent
921 @t{(group} ([@var{OPTIONS@dots{}}]) @var{ITEMS@dots{}}@t{)}
923 @cindex Text, in groups
924 @cindex Options, in groups
925 @cindex Groups, in groups
926 @var{OPTIONS} are key/value pairs. @var{ITEMS} simply are arbitrary
927 text, option or sub-group descriptions as we've just seen.
929 The following @var{OPTIONS} are currently available.
930 @table @t
931 @item :header
932 @cindex Group Header
933 @cindex Header, in group
934 @foindex{defgroup,:header}@c
935 A string which will be displayed above the group's contents in the help
936 string. The same formatting recommendations as for arbitrary text apply
937 (@pxref{Text}).
938 @item :hidden
939 @cindex Hidden Groups
940 @cindex Groups, hidden
941 @foindex{defgroup,:hidden}@c
942 @cindex Help String
943 @cindex Built-In Groups
944 @cindex Groups, built-in
945 @bioindex{help}
946 When non-@code{nil}, the group won't appear in the help string. Hidden
947 groups can still be displayed individually though (@pxref{Help}). For
948 instance, the @clon{} built-in group is hidden in the regular help
949 string, but the @bioption{help} option still displays it individually.
950 @end table
952 @node Built-In Option Types, Advanced Synopsis Creation, Synopsis Items, Synopsis Definition
953 @subsection Built-In Option Types
954 @cindex Built-In Option Types
955 @cindex Options, built-in types
956 @cindex Option Types, built-in
957 In this section, we will review all the built-in option types that
958 @clon{} provides, along with their corresponding properties. You can use
959 them directly in your synopsis description. For adding personal option
960 types to @clon{}, see @ref{New Option Types}.
962 @menu
963 * Common Properties::                   For all options
964 * Flags::                               Built-in options without arguments
965 * Common Valued Option Properties::     For all valued options
966 * Built-In Valued Options::             Built-in options with arguments
967 @end menu
969 @node Common Properties, Flags, Built-In Option Types, Built-In Option Types
970 @subsubsection Common Properties
971 @cindex Options, common properties
972 @cindex Common Option Properties
973 @clsindex{option}
974 All option types in @clon{}, including those you define yourself
975 (@pxref{New Option Types}), have a set of basic, common properties. Here
976 is a list of them.
978 @table @code
979 @item :short-name
980 @copindex{:short-name}
981 The option's short name. A string or @code{nil}.
982 @item :long-name
983 @copindex{:long-name}
984 The option's long name. A string or @code{nil}.
985 @item :description
986 @copindex{:description}
987 The option's descriptive text. A string or @code{nil}. The same
988 formatting recommendations as for arbitrary text apply (@pxref{Text}).
989 @item :env-var
990 @copindex{:env-var}
991 The option's associated environment variable. A string or @code{nil}.
992 @item :hidden
993 @copindex{:hidden}
994 @cindex Hidden Options
995 @cindex Options, hidden
996 @cindex Help String
997 When non-@code{nil}, the option won't appear in the help string. Hidden
998 options can still be displayed individually though (@pxref{Help}).
999 @end table
1001 Note that an option is required to have at least one name (either short
1002 or long). Non-@code{nil} but empty names are also prohibited, and of
1003 course, a short name cannot begin with a dash (otherwise, it would be
1004 mistaken for a long name, but did I really need to mention this?).
1006 @node Flags, Common Valued Option Properties, Common Properties, Built-In Option Types
1007 @subsubsection Flags
1008 @oindex{Flags,flag}
1009 In @clon{}, options that don't take any argument are of type
1010 @code{flag}. These options don't provide additional properties on top of
1011 the common set described in @ref{Common Properties}. All properties
1012 default to @code{nil}.
1014 @node Common Valued Option Properties, Built-In Valued Options, Flags, Built-In Option Types
1015 @subsubsection Common Valued Option Properties
1016 @cindex Valued Options
1017 @cindex Options, valued
1018 @clsindex{valued-option}
1019 All non-flag options in @clon{} are said to be @dfn{valued}. All valued
1020 options, including those you define yourself (@pxref{New Option Types}),
1021 share a set of additional properties. Here is a list of them.
1023 @cindex Valued Options, common properties
1024 @cindex Common Valued Option Properties
1025 @cindex Options, valued, common properties
1026 @table @code
1027 @item :argument-name
1028 @cvopindex{:argument-name}
1029 The name of the option's argument, as it appears in the help string. It
1030 defaults to @code{"ARG"}, so that for instance, a @samp{name} option
1031 would appear like this: @samp{--name=ARG}.
1032 @item :argument-type
1033 @cvopindex{:argument-type}
1034 The status of the argument. Possible values are @code{:required} (the
1035 default) and @code{:mandatory} which are synonyms, or @code{:optional}.
1036 @item :fallback-value
1037 @cvopindex{:fallback-value}
1038 @cindex Values, source, fallback
1039 @item :default-value
1040 @cvopindex{:default-value}
1041 @cindex Values, source, default
1042 The option's fallback and default values. Remember that a fallback value
1043 only makes sense when the argument is optional. Besides, also when the
1044 argument is optional, you need to provide at least a fallback or a
1045 default value (or both of course; see @enduserref{Value Sources}).
1046 @end table
1048 @node Built-In Valued Options, , Common Valued Option Properties, Built-In Option Types
1049 @subsubsection Built-In Valued Options
1050 @cindex Option Types, valued
1051 @cindex Built-In Option Types, valued
1052 @cindex Options, built-in types, valued
1053 @cindex Option Types, built-in, valued
1054 @clon{} currently defines 6 built-in valued option types. These option
1055 types may change the default value for some common properties, and / or
1056 provide additional properties of their own. All of this is described
1057 below.
1059 @table @code
1060 @item stropt
1061 @voindex{Strings,stropt}@c
1062 @cvopindex{:argument-name}@c
1063 This option type is for options taking strings as their argument. String
1064 options don't provide any additional properties, but their default
1065 argument name is changed from @code{"ARG"} to @code{"STR"}.
1066 @item lispobj
1067 @voindex{Lisp Objects,lispobj}@c
1068 @cvopindex{:argument-name}@c
1069 @vopindex{Lisp Objects,lispobj,:typespec}@c
1070 @bioindex{line-width}@c
1071 This option type is for options taking any kind of Lisp object as their
1072 argument. @code{lispobj} options change their default argument name from
1073 @code{"ARG"} to @code{"OBJ"}. Also, they provide an additional property
1074 called @code{:typespec} which must be a @cl{} type specifier that the
1075 argument must satisfy. It defaults to @code{t}. Look at the
1076 @bioption{line-width} built-in option for an example.
1077 @item enum
1078 @voindex{Enumerations,enum}@c
1079 @cvopindex{:argument-name}@c
1080 @vopindex{Enumerations,enum,:enum}@c
1081 @bioindex{version}@c
1082 This option type is for options taking values from an enumerated set of
1083 keywords. @code{enum} options change their default argument name from
1084 @code{"ARG"} to @code{"TYPE"}. Also, they provide an additional property
1085 called @code{:enum} to store the list of @cl{} keywords enumerating the
1086 possible values. The end-user does not use a colon when providing an
1087 argument to an @code{enum} option. Only the keyword's name. The end-user
1088 also has the ability to abbreviate the possible values. An empty
1089 argument is considered as an abbreviation for the first element in the
1090 set. Look at the @bioption{version} built-in option for an example.
1091 @item path
1092 @bioindex{search-path}@c
1093 @bioindex{theme}@c
1094 @voindex{Paths,path}@c
1095 @cvopindex{:argument-name}@c
1096 @vopindex{Paths,path,:type}@c
1097 This option type is for options taking a colon-separated list of
1098 pathnames as argument. @code{path} options change their default argument
1099 name from @code{"ARG"} to @code{"PATH"}. Also, they provide an
1100 additional property called @code{:type} which specifies the kind of path
1101 which is expected. Possible values are: @code{:file}, @code{:directory},
1102 @code{:file-list}, @code{:directory-list} or @code{nil} (meaning that
1103 anything is allowed). Null paths are allowed, and may be provided by an
1104 empty argument. Look at the @bioption{search-path} and
1105 @bioption{theme} built-in options for examples.
1106 @item switch
1107 @voindex{Switches,switch}@c
1108 @cvopindex{:argument-name}@c
1109 @cvopindex{:argument-type}@c
1110 @vopindex{Switches,switch,:argument-style}@c
1111 This option type is for Boolean options. @code{switch} options change
1112 their default argument type from required to optional and provide a
1113 fallback value of @code{t} automatically for optional arguments.
1114 @code{switch} options provide a new property called
1115 @code{:argument-style}. Possible values are @code{:yes/no} (the
1116 default), @code{:on/off}, @code{:true/false}, @code{:yup/nope},
1117 @code{:yeah/nah}. This property affects the way the argument name and
1118 true or false values are advertized in help strings. However, all
1119 possible arguments forms (@pxenduserref{Switches}) are always available
1120 to all switches.
1121 @item xswitch
1122 @voindex{Extended Switches,xswitch}@c
1123 @cvopindex{:argument-name}@c
1124 @cvopindex{:argument-type}@c
1125 @vopindex{Extended Switches,xswitch,:argument-style}@c
1126 @vopindex{Extended Switches,xswitch,:enum}@c
1127 @bioindex{highlight}@c
1128 This option type stands for @dfn{extended} switch. Extended switches
1129 result from the mating of a male switch and a female enumeration, or the
1130 other way around (elementary decency prevents me from describing this
1131 mating process in detail): their possible values are either Boolean or
1132 from an @code{:enum} property as in the case of @code{enum} options. As
1133 simple switches, @code{xswitch} options change their default argument
1134 type from required to optional and provide a fallback value of @code{t}
1135 automatically for optional arguments. They also provide the
1136 @code{:argument-style} property. Contrary to switches, however, this
1137 property does not affect the argument name. It only affects the way true
1138 or false values are displayed in help strings. Look at the
1139 @bioption{highlight} built-in option for an example.
1140 @end table
1142 @node Advanced Synopsis Creation, , Built-In Option Types, Synopsis Definition
1143 @subsection Advanced Synopsis Creation
1144 @findex defsynopsis
1145 The fact that @code{defsynopsis} lets you define things in a
1146 @emph{declarative} way has not escaped you. Declarative is nice but
1147 sometimes it gets in the way, so it is time to see how things work under
1148 the hood. Every item in a synopsis is in fact implemented as an object
1149 (an instance of some class), so it turns out that @code{defsynopsis}
1150 simply is a convenience wrapper around the corresponding constructor
1151 functions for all such objects. Instead of using @code{defsynopsis}, you
1152 can then use those constructor functions explicitely.
1154 @menu
1155 * Constructors::        The expansion of defsynopsis
1156 * Advantages::          Yes, but why?
1157 * Group Definition::    The declarative way
1158 @end menu
1160 @node Constructors, Advantages, Advanced Synopsis Creation, Advanced Synopsis Creation
1161 @subsubsection Constructors
1162 Let's have a look at the expansion of @code{defsynopsis} from the quick
1163 start example (@pxref{Quick Start}).
1165 The original code is like this:
1167 @cartouche
1168 @verbatim
1169 (defsynopsis (:postfix "FILES...")
1170   (text :contents "A very short program.")
1171   (group (:header "Immediate exit options:")
1172     (flag :short-name "h" :long-name "help"
1173           :description "Print this help and exit.")
1174     (flag :short-name "v" :long-name "version"
1175           :description "Print version number and exit.")))
1176 @end verbatim
1177 @end cartouche
1179 And once the macro is expanded, it will look like this:
1181 @cfindex make-synopsis
1182 @cfindex make-text
1183 @cfindex make-group
1184 @cfindex make-flag
1185 @findex defsynopsis@r{, expansion}
1186 @cartouche
1187 @verbatim
1188 (make-synopsis :postfix "FILES..."
1189   :item (make-text :contents "A very short program.")
1190   :item (make-group :header "Immediate exit options:"
1191           :item (make-flag :short-name "h"
1192                            :long-name "help"
1193                            :description "Print this help and exit.")
1194           :item (make-flag :short-name "v"
1195                            :long-name "version"
1196                            :description "Print version number and exit.")))
1197 @end verbatim
1198 @end cartouche
1200 As you can see, every synopsis element has a corresponding
1201 @code{make-@var{SOMETHING}} constructor, and the keywords used here and
1202 there in @code{defsyopsis} are in fact initargs to those constructors.
1203 We now examine those constructors in greater detail.
1205 @cindex Options, creation
1206 @defun make-text [@code{:hidden} BOOL] @code{:contents} STRING
1207 @cfsubindex{make-text}
1208 @cfiaindex{make-text,:contents}
1209 @cfiaindex{make-text,:hidden}
1210 Create an arbitrary text object, possibly hidden, whose contents is
1211 @var{STRING}.
1212 @end defun
1214 @c #### FIXME: I would like an environment without indexing here.
1215 @defun make-@var{OPTION} :INITARG INITVAL@dots{}
1216 @cfsubindex{make-@var{OPTION}}
1217 @cfindex make-flag
1218 @cfindex make-stropt
1219 @cfindex make-lispobj
1220 @cfindex make-enum
1221 @cfindex make-path
1222 @cfindex make-switch
1223 @cfindex make-xswitch
1224 Create a new @var{OPTION} object, @var{OPTION} being any built-in option
1225 type (@code{flag}, @code{stropt} @etc{}, see @ref{Built-In Valued
1226 Options}) or user-defined one (@pxref{New Option Types}). For a list of
1227 available initialization arguments (depending on the option type), see
1228 @ref{Built-In Option Types}.
1229 @end defun
1231 @defun make-group [@code{:header} STRING @code{:hidden} BOOL] @
1232 @code{:item} ITEM1 @code{:item} ITEM2@dots{}
1233 @cfsubindex{make-group}
1234 @cfiaindex{make-group,:header}
1235 @cfiaindex{make-group,:hidden}
1236 @cfiaindex{make-group,:item}
1237 @cindex Help String
1238 Create a group object, possibly hidden, whose header is @var{STRING}.
1239 Every @var{ITEM} is an arbitrary text object, option object or group
1240 object. The order is important as it determines the display of the help
1241 string.
1242 @end defun
1244 @defun make-synopsis [@code{:postfix} STRING] @
1245 @code{:item} ITEM1 @code{:item} ITEM2@dots{}
1246 @cfsubindex{make-synopsis}
1247 @cfiaindex{make-synopsis,:postfix}
1248 @cfiaindex{make-synopsis,:item}
1249 @cindex Help String
1250 Create a synopsis object whose postfix is @var{STRING}. Every @var{ITEM} is
1251 an arbitrary text object, option object or group object. The order is
1252 important as it determines the display of the help string.
1253 @end defun
1255 In fact, the @code{defsynopsis} macro allows you to freely mix
1256 declarative forms, constructor calls or whatever Lisp code you may want
1257 to use. The way this works is as follows: if a synopsis @var{ITEM}
1258 (@pxref{Synopsis Items}) is a list whose @code{car} is @code{text},
1259 @code{group}, or any option type (inluding those you define yourselves;
1260 see @ref{New Option Types}), then the @var{ITEM} is expanded as
1261 explained earlier. Otherwise, it is just left @emph{as-is}.
1263 To sum up, here's a example of things you can do in @code{defsynopsis}.
1265 @cartouche
1266 @verbatim
1267 (com.dvlsoft.clon:defsynopsis ()
1268   (flag #| ... |#)
1269   *my-great-option*
1270   (setq *another-option* (com.dvlsoft.clon:make-switch #| ... |#)))
1271 @end verbatim
1272 @end cartouche
1275 @node Advantages, Group Definition, Constructors, Advanced Synopsis Creation
1276 @subsubsection Advantages
1277 @findex defsynopsis
1278 So, why would you want to use constructors directly or mix declarative
1279 and imperative forms in @code{defsynopsis}? There are several reasons
1280 for doing so.
1281 @enumerate
1282 @item
1283 Some people prefer to declare (or should I say, create) their arbitrary
1284 texts, options and groups locally, in files, modules or ASDF components
1285 where they belong. In such a case, you need to keep references to the
1286 corresponding objects in order to compute the synopsis in the end.
1287 @item
1288 Since using constructors explicitely allows you to keep references to
1289 the created objects, these objects can be @emph{reused}. For instance,
1290 you can use the same text at different places, you can also use a single
1291 option several times, or even a single group several times so that its
1292 items appear in different places @etc{} Note that @clon{} knows its way
1293 around multiple occurrences of the same object: even if you use the same
1294 option object several times in a synopsis, @clon{} only maintains a
1295 single option definition.
1296 @end enumerate
1298 @node Group Definition, , Advantages, Advanced Synopsis Creation
1299 @subsubsection Group Definition
1300 There is one last point we need to address in order to complete this
1301 section. There might be times when you need to manipulate an explicit
1302 group object, but the object itself can still be created in a
1303 declarative (or mixed) way because you don't need to keep references on
1304 its items. For this, @clon{} provides a macro called @code{defgroup}.
1306 @defmac defgroup (OPTIONS@dots{}) ITEMS@dots{}
1307 @cindex Groups, in synopsis
1308 @fiindex{defsynopsis,group}
1309 @foindex{defgroup,:header}
1310 @foindex{defgroup,:hidden}
1311 Define a new group and return it. This macro behaves exactly like the
1312 @code{group} form in a call to @code{defsynopsis} (@pxref{Groups}). In
1313 fact, an intermediate step in the expansion of the @code{defsynopsis}
1314 macro is to transform @code{group} forms into @code{defgroup} macro
1315 calls. As for @code{defsynopsis}, @code{defgroup} allows you to mix
1316 declarative forms, constructor calls or any kind of Lisp code.
1317 @end defmac
1321 @c ----------------
1322 @c Context Creation
1323 @c ----------------
1324 @node Context Creation, Integrity Checks, Synopsis Definition, Using Clon
1325 @section Context Creation
1327 @cindex Initialization Phase
1328 @cindex Phase, initialization
1329 @cindex Context
1330 Step two of the @clon{} initialization phase consists in creating a
1331 @dfn{context}. A context is an object representing a particular instance
1332 of your program, for example (and most notably) with an actual
1333 @cmdline{} as the user typed it.
1335 @menu
1336 * Making A Context::            The Constructor function
1337 * Contextual Information::      Interesting context slots
1338 @end menu
1340 @node Making A Context, Contextual Information, Context Creation, Context Creation
1341 @subsection Making A Context
1343 @cfindex{make-context}
1344 You create a context with the @code{make-context} function.
1346 @defun make-context
1347 @cfsubindex{make-context}
1348 Create a new context. That's it.
1349 @end defun
1351 @node Contextual Information, , Making A Context, Context Creation
1352 @subsection Contextual Information
1354 Once a context object is created, you have access to some interesting
1355 contextual information.
1357 @menu
1358 * Program Name::                As it appear on the command-line
1359 * Command-Line Remainder::      The non-options part
1360 * Command-Line Polling::        Whether something is left
1361 @end menu
1363 @node Program Name, Command-Line Remainder, Contextual Information, Contextual Information
1364 @subsubsection Program Name
1365 The application's program name, as it appears on the @cmdline{}, may be
1366 accessed from @clon{}. You may find it easier to do this way, as @clon{}
1367 wraps around implementation-dependent access methods to @code{argv[0]}.
1369 @findex progname
1370 In order to retrieve @code{argv[0]}, use the @code{progname} function
1371 like this: @code{(progname)}.
1373 @node Command-Line Remainder, Command-Line Polling, Program Name, Contextual Information
1374 @subsubsection Command-Line Remainder
1375 @cindex Remainder, of command-line
1376 @cindex Command-Line, remainder
1377 In the case your @cmdline{} has a remainder (that is, a non-options
1378 part; see @enduserref{Option Separator} and @ref{Synopsis Items}), you
1379 may need to access it in order to process it independently from @clon{}.
1380 Since @clon{} is responsible for parsing the @cmdline{}, it is also in
1381 charge of figuring out where the remainder of the @cmdline{} begins.
1383 @findex remainder
1384 The @cmdline{} remainder is known to @clon{} as soon as a context is
1385 created. You can retrieve it by using the @code{remainder} function like
1386 this: @code{(remainder)}. The remainder is provided as a list of strings.
1388 @node Command-Line Polling, , Command-Line Remainder, Contextual Information
1389 @subsubsection Command-Line Polling
1390 @cindex Polling, of command-line
1391 @cindex Command-Line, polling
1393 @clon{} provides two utility functions to inquire on the current status
1394 of the @cmdline{}.
1396 @findex cmdline-options-p
1397 @findex cmdnline-p
1398 The function @code{cmdline-options-p} returns true if there are still
1399 unprocessed options on the @cmdline{}. The function @code{cmdline-p}
1400 returns true if there's @emph{anything} left on the @cmdline{}, that is,
1401 either unprocessed options, or a remainder. A potential use of
1402 @code{cmdline-p} at a very early stage of your application could be to
1403 automatically display a help string if the @cmdline{} is effectively
1404 empty.
1407 @c ----------------
1408 @c Integrity Checks
1409 @c ----------------
1410 @node Integrity Checks, Option Retrieval, Context Creation, Using Clon
1411 @section Integrity Checks
1412 @findex defsynopsis
1413 @cfindex{make-context}
1414 At this point, you know about the two necessary steps to initialize
1415 @clon{}: defining a synopsis and creating a context. If you paid
1416 attention to the quick start application (@pxref{Quick Start}), you may
1417 have noticed that @code{defsynopsis} was called as a top-level form
1418 whereas @code{make-context} was called from the function @code{main}. So
1419 why the difference?
1421 First, I hope that you see why a context cannot be created as a toplevel
1422 form. If you do that, you will end-up creating a context relevant to the
1423 Lisp environment from which the application is created, not run.
1425 The synopsis, on the other hand, could be defined either as a toplevel
1426 form, as done in the quick start and the demo programs, or in the
1427 function @code{main}, just before making a context. There is a very good
1428 reason to prefer a toplevel form however: that reason is called
1429 ``integrity checks''.
1431 When you define a synopsis (or any synopsis item, for that matter),
1432 @clon{} performs a number of checks to make sure that you're making a
1433 sensible use of the library. In fact, the number of semantic mistakes
1434 that you can make is quite puzzling. You could for instance define
1435 several options with identical names, forget to provide a fallback or
1436 default value when it is required, provide invalid fallback or default
1437 values, and the list goes on and on. These are just a few examples but
1438 there are many more, and @clon{} checks all of those (I think).
1440 Since those mistakes relate to the definition of the application itself,
1441 they do not depend on a particular execution of it. Consequently, the
1442 sooner @clon{} catches them, the better. If you define your
1443 application's synopsis as a toplevel form, @clon{} will be able to
1444 perform its integrity checks when the application is created, not only
1445 when it is used. In other words, you won't be able to get a working
1446 application until your use of @clon{} is semantically correct.
1448 This is why it is strongly recommended to create synopsis from toplevel
1449 forms, and this also explains why @clon{} chooses @emph{not} to provide
1450 an @code{initialize} function that would wrap around @code{defsynopsis}
1451 and @code{make-context} together.
1455 @c ----------------
1456 @c Option Retrieval
1457 @c ----------------
1458 @node Option Retrieval, Help, Integrity Checks, Using Clon
1459 @section Option Retrieval
1460 @cindex Runtime Phase
1461 @cindex Phase, runtime
1462 @cindex Retrieval, of options
1463 @cindex Options Retrieval
1465 During the runtime phase of @clon{}, your main activity will be to
1466 retrieve options and their values. @clon{} provides two techniques for
1467 retrieving options: you can request the value for a specific option
1468 directly, or you can process the @cmdline{} sequentially, which is the
1469 more traditional approach.
1471 @cindex Command-Line
1472 @findex cmdline
1473 Both of these techniques can be freely combined together at any time,
1474 because @clon{} keeps track of the current status of the @cmdline{}. In
1475 fact, @clon{} never works on the original @cmdline{}, but uses a mutable
1476 @emph{copy} of it after parsing. If you want to access the real
1477 @cmdline{} of your application (except for the compiler-specific
1478 options, see @ref{Not Dumping Executables}), you may use the
1479 @code{cmdline} function, which is a wrapper around an
1480 implementation-dependent way to access it.
1483 Finally, remember that the @cmdline{} is scanned from left to right
1484 during option retrieval (@pxenduserref{Option Retrieval}).
1486 @menu
1487 * Explicit Retrieval::          Accessing options by name
1488 * Sequential Retrieval::        Accessing options in order
1489 @end menu
1491 @node Explicit Retrieval, Sequential Retrieval, Option Retrieval, Option Retrieval
1492 @subsection Explicit Retrieval
1493 @cindex Options Retrieval, explicit
1494 @cindex Retrieval, of options, explicit
1495 Since @clon{} lets you retrieve options on demand (at any time), it
1496 makes sense to be able to request the value of a specific option
1497 explicitely. For instance, you might want to try the @samp{--help}
1498 option first, without looking at the rest of the @cmdline{} because the
1499 application will in fact quit immediately after having displayed the
1500 help string.
1502 @defun getopt :KEY VALUE@dots{}
1503 Retrieve the value of a specific option. The following @var{:KEY}s are
1504 currently available.
1506 @table @code
1507 @item :short-name
1508 @item :long-name
1509 @fkindex{getopt,:short-name}
1510 @fkindex{getopt,:long-name}
1511 Use one of these 2 keys to specify the name of the option you wish to
1512 retrieve.
1513 @item :option
1514 @fkindex{getopt,:option}
1515 Alternatively, you can use a reference to an option object
1516 (@pxref{Constructors}).
1517 @end table
1519 This function return two values: the option's value and the value's
1520 source (@pxenduserref{Value Sources}).
1521 @end defun
1523 The value's source may have the following forms:
1524 @table @code
1525 @item (:cmdline @var{NAME})
1526 @cindex Values, source, @cmdline{}
1527 This is for options found on the @cmdline{}. @var{NAME} is the name used
1528 on the @cmdline{}. It can be the option's long or short name, or a
1529 completed long name if the option's name was abbreviated. A completed
1530 name displays the omitted parts in parentheses (@code{"he(lp)"} for
1531 instance).
1532 @item (:fallback @var{NAME})
1533 @cvopindex{:fallback-value}
1534 @cindex Values, source, fallback
1535 The same but when the fallback value is used, that is, when an option is
1536 not provided with its (optional) argument.
1537 @item (:default @var{NAME})
1538 @cvopindex{:default-value}
1539 @cindex Values, source, default
1540 The same, but when the default value is used (because there is no
1541 fallback).
1542 @item (:environment @var{VAR})
1543 @copindex{:env-var}
1544 @cindex Values, source, environment
1545 This is for options not found on the @cmdline{} but for which there is
1546 an associated environment variable set in the application's environment.
1547 @var{VAR} is the name of the corresponding environment variable.
1548 @item :default
1549 @cvopindex{:default-value}
1550 @cindex Values, source, default
1551 This is for options not found anywhere, but for which a default value
1552 was provided.
1553 @end table
1555 @oindex{Flags,flag}
1556 @findex getopt
1557 Note that because flags don't take any argument, @code{getopt} returns a
1558 virtual value of @code{t} when they are found or a corresponding
1559 environment variable exists in the environment. For the same reason, a
1560 flag's value source may ony be @code{(:cmdline @var{NAME})} or
1561 @code{(:environment @var{VAR})}.
1563 @findex getopt
1564 When an option is not found anywhere and there is no default value,
1565 @code{getopt} just returns nil (no second value). Also, note that when
1566 your option accepts @code{nil} as a value, you @emph{need} to handle the
1567 second retrun value to make the difference between an option not found,
1568 and an actual value of @code{nil}.
1571 @node Sequential Retrieval, , Explicit Retrieval, Option Retrieval
1572 @subsection Sequential Retrieval
1573 @cindex Options Retrieval, sequential
1574 @cindex Retrieval, of options, sequential
1575 The more traditional approach to option retrieval is to scan the
1576 @cmdline{} for options in their order of appearance. @clon{} supports
1577 this by providing you with one function and two macros, as explained
1578 below.
1580 @defun getopt-cmdline
1581 Get the @dfn{next} @cmdline{} option, that is, the first option on the
1582 @cmdline{} that has not been previously retrieved, either explicitely or
1583 sequentially.
1585 When there are no more options on the @cmdline{}, this function returns
1586 @code{nil}. Otherwise, four values are returned: the corresponding
1587 option object from the synopsis definition (@pxref{Constructors}), the
1588 name used on the @cmdline{}, the option's value and the value source
1589 (@code{:cmdline}, @code{:fallback} or @code{:default}). As in the case
1590 of explicit retrieval (@pxref{Explicit Retrieval}), the option's name
1591 may be completed in case of abbreviation.
1593 @rfindex{short-name}
1594 @rfindex{long-name}
1595 @copindex{:short-name}
1596 @copindex{:long-name}
1597 Unless you keep references to all your option objects (and thus can
1598 compare them directly to the one returned by this function), you can
1599 still identify the retrieved option by using the @code{short-name} and
1600 @code{long-name} readers on it: simply use @code{(long-name
1601 @var{OPTION})} or @code{(short-name @var{OPTION})} and you will get the
1602 corresponding strings.
1603 @end defun
1605 @defmac multiple-value-getopt-cmdline (OPTION NAME VALUE SOURCE) BODY
1606 Evaluate @var{BODY} with @var{OPTION}, @var{NAME}, @var{VALUE} and
1607 @var{SOURCE} bound to the values returned by the @code{getopt-cmdline}
1608 function above. Note that @var{BODY} is not evaluated if there was no
1609 remaining option on the @cmdline{}, so you don't need to conditionalize
1610 on @var{OPTION} being @code{null} yourself.
1611 @end defmac
1613 @defmac do-cmdline-options (OPTION NAME VALUE SOURCE) BODY
1614 As above, but loop over all @cmdline{} options.
1615 @end defmac
1618 @c ----
1619 @c Help
1620 @c ----
1621 @node Help, , Option Retrieval, Using Clon
1622 @section Help
1623 @cindex Help String
1624 One of the first motivations in the design of @clon{} was to automate
1625 the generation of the help string, which is a very boring maintenance
1626 task to do by hand. The application's synopsis contains all the
1627 necessary information to do so. In order to print your application's
1628 help string, use the @code{help} function.
1630 @defun help [@code{:item} ITEM]
1631 @bioindex{search-path}
1632 @bievindex{SEARCH_PATH}
1633 @bioindex{highlight}
1634 @bievindex{HIGHLIGHT}
1635 @bioindex{theme}
1636 @bievindex{THEME}
1637 @bioindex{line-width}
1638 @bievindex{LINE_WIDTH}
1639 Print the application's help string. Printing honors the search path,
1640 theme, line width and highlight settings provided by the corresponding
1641 built-in options (@pxenduserref{Theme Mechanism}).
1642 @end defun
1644 @fkindex{help,:item}
1645 By default, @code{help} prints the whole application help string,
1646 excluding hidden items. However, if you have kept a reference to any
1647 synopsis item (option, text, group), you can pass it as the value of the
1648 @code{:item} key, and @clon{} will only print the help string for that
1649 particular item. In this case however, the hidden state of the item is
1650 discarded (but @emph{not} the ones of sub-items).
1652 @bioindex{help}
1653 @cindex Built-In Groups
1654 @cindex Groups, built-in
1655 @cindex Hidden Groups
1656 @cindex Groups, hidden
1657 For instance, the @clon{} built-in group is normally hidden, so it
1658 doesn't show up in the global help string, but the @bioption{help}
1659 option uses the @code{help} function on it explicitely, so it discards
1660 its hidden state.
1662 Here is a potentially useful application of hidden groups in conjunction
1663 with the @code{:item} key. Look at ImageMagick's @file{convert}
1664 program's help string for instance: it is 276 lines long. Gosh. The help
1665 string is decomposed into several categories: image settings, image
1666 operators, misc options @etc{}. If I were to implement this program, I
1667 would rather have the @option{--help} option display an overview of the
1668 program, advertise @option{--version} and a couple of others, and I
1669 would then implement @option{--help} as an enumeration for listing every
1670 option category individually (they would normally be stored in hidden
1671 groups). The user could then use @option{--help=settings},
1672 @option{--help=operators} and so on to display only the category she's
1673 interested in.
1675 Finally, here is potentially useful application of hidden options that
1676 are never ever displayed in any help string whatsoever, and I mean,
1677 like, ever. This is the perfect tool for backdoor'ing a program. For
1678 instance, if you ever need to implement a
1679 @option{--discard-all-security-measures-and-blow-the-nuke} option, then
1680 you'd better have it hidden@dots{}
1684 @c ====================================================================
1685 @c Extending Clon
1686 @c ====================================================================
1687 @node Extending Clon, Advanced Usage, Using Clon, Top
1688 @chapter Extending Clon
1690 As you know, @clon{} already provides seven built-in option types: flags
1691 and six other types for valued options (@pxref{Built-In Valued
1692 Options}). After using @clon{} for a while, you may find that however
1693 brilliant and perfectly designed it is, none of the provided built-in
1694 types fullfill your requirements exactly. There are two ways around
1695 this: the right way and the wrong way (hint).
1697 @voindex{Strings,stropt}
1698 The wrong, although perhaps quicker way would be to use the
1699 @code{stropt} option type to simply retrieve unprocessed string values,
1700 and then do whatever tweaking required on them. In doing so, you risk
1701 reinventing some of @clon{}'s wheels.
1703 The right way is to define a new option type. Properly defined option
1704 types are a good thing because they allow for reusability and also
1705 extensibility, since new option types can always be defined on top of
1706 others.
1707 @voindex{Enumerations,enum}
1708 In this chapter we explain how to extend @clon{} by providing new option
1709 types. We illustrate the process with the example of the built-in
1710 @code{enum} one.
1712 @cindex Valued Options
1713 @cindex Options, valued
1714 @oindex{Flags,flag}
1715 Oh, and I almost forgot. I hope it is obvious to everyone that new
1716 option types are always @emph{valued}. There's no point in extending
1717 @clon{} with options that don't take any arguments, since we already
1718 have flags.
1720 @menu
1721 * New Option Types::    In four steps
1722 * Extension Tips::      Some advice
1723 @end menu
1726 @c ----------------
1727 @c New Option Types
1728 @c ----------------
1729 @node New Option Types, Extension Tips, Extending Clon, Extending Clon
1730 @section New Option Types
1731 @cindex Option Types, in files
1732 @cindex Files, one per option type
1733 @pkgindex{com.dvlsoft.clon}
1734 From a software engineering point of view, it is better to implement new
1735 option types in a file of their own, preferably named after the option
1736 type itself, and to put this file in the @clon{} package, like this:
1738 @cartouche
1739 @verbatim
1740 (in-package :com.dvlsoft.clon)
1741 @end verbatim
1742 @end cartouche
1744 Creating your own option type involves 5 steps: providing a class for
1745 them, implementing three protocols related to argument/value tweaking,
1746 and providing a constructor function. We now review those 5 steps in
1747 order.
1749 @menu
1750 * New Option Classes::                  Step 1
1751 * Value Check Protocol::                Step 2
1752 * Argument Conversion Protocol::        Step 3
1753 * Error Management::                    In-between steps coffee time!
1754 * Value Stringification Protocol::      Step 4
1755 * Constructor Functions::               Step 5
1756 @end menu
1758 @node New Option Classes, Value Check Protocol, New Option Types, New Option Types
1759 @subsection New Option Classes
1760 @clsindex{option}
1761 @clsindex{valued-option}
1762 @clon{} maintains a class hierarchy for all option types. The mother of
1763 all option types is the @code{option} abstract class. It handles the
1764 options'short and long names, description and associated environment
1765 variable (@pxref{Common Properties}). Valued options inherit from an
1766 abstract subclass of @code{option} called @code{valued-option}. This
1767 class handles the option's argument name and status (optional or
1768 mandatory), fallback and default values (@pxref{Common Valued Option
1769 Properties}).
1771 @cindex User-Defined Option Classes
1772 @cindex Option Classes, user-defined
1773 In order to create a new option type, use the @code{defoption} macro.
1775 @defmac defoption CLASS SUPERCLASSES SLOTS &rest OPTIONS
1776 Create a new option CLASS and register it with @clon{}.
1777 Syntactically, thismacro behaves like @code{defclass}. Option types
1778 created like this implicitely inherit from @code{valued-option} and in
1779 turn @code{option}, so you don't need to put them explicitely in the
1780 @var{SUPERCLASSES} list.
1781 @end defmac
1783 Let's look at the enumeration example now.
1785 @cartouche
1786 @verbatim
1787 (defoption enum (enum-base)
1788   ((argument-name ;; inherited from the VALUED-OPTION class
1789     :initform "TYPE"))
1790   (:documentation "The ENUM class.
1791 This class implements options whose values belong to a set of keywords."))
1792 @end verbatim
1793 @end cartouche
1795 @voindex{Enumerations,enum}
1796 @vopindex{Enumerations,enum,:enum}
1797 @voindex{Extended Switches,xswitch}
1798 @vopindex{Extended Switches,xswitch,:enum}
1799 @clsindex{enum-base}
1800 As you can see, this class inherits from @code{enum-base}, which is the
1801 class handling the @code{:enum} property. The reason for this split is
1802 that there are currently two option types providing enumeration-like
1803 facility: @code{enum} and @code{xswitch}, so @code{xswitch} also
1804 inherits from @code{enum-base}.
1806 @clsindex{valued-option}
1807 @cvopindex{:argument-name}
1808 There are no new slots in this class, but the @code{argument-name} slot
1809 provided by the @code{valued-option} class has its initform changed from
1810 @code{"ARG"} to @code{"TYPE"}.
1812 @node Value Check Protocol, Argument Conversion Protocol, New Option Classes, New Option Types
1813 @subsection Value Check Protocol
1814 @cindex Value Check Protocol
1815 @cindex Protocols, value check
1816 Now that we have our new option class, we need to implement the
1817 so-called @dfn{value check} protocol. This protocol is used to make sure
1818 that values provided for options of your new type actually comply with
1819 the type in question. Values going through this protocol are fallback
1820 values, default values, and values provided from a debugger restart
1821 (@pxenduserref{Error Management}). In the case of fallback and default
1822 values (which, by the way, are provided by @emph{you}, the @clon{}
1823 user), the check is performed only once, when the option object is
1824 created. Values provided from a debugger restart come from the
1825 application end-user, and hence are checked every time.
1827 The value check protocol is implemented through a @code{check} generic
1828 function for which you must provide a method.
1830 @deffn {Generic Function} check OPTION VALUE
1831 @gfsubindex{check}
1832 @ecindex invalid-value
1833 Check that @var{VALUE} is valid for @var{OPTION}. If @var{VALUE} is
1834 valid, return it. Otherwise, raise an @code{invalid-value} error.
1835 @end deffn
1837 As you can see, you need to provide a method with the first argument
1838 specialized to your new option type. This method must return @var{VALUE}
1839 if it is okay, and raise an @code{invalid-value} error otherwise.
1841 @ecindex invalid-value
1842 @clon{} maintains a hierarchy of error conditions. The
1843 @code{invalid-value} error condition is defined like this:
1845 @cartouche
1846 @verbatim
1847 (define-condition invalid-value (option-error)
1848   ((value :documentation "The invalid value."
1849           :initarg :value
1850           :reader value)
1851    (comment :documentation "An additional comment about the error."
1852             :type string
1853             :initarg :comment
1854             :reader comment))
1855   (:report (lambda (error stream)
1856              (format stream "Option ~A: invalid value ~S.~@[~%~A~]"
1857                (option error) (value error) (comment error))))
1858   (:documentation "An invalid value error."))
1859 @end verbatim
1860 @end cartouche
1862 @ecindex invalid-value
1863 @ecsindex{invalid-value,value}
1864 @ecsindex{invalid-value,comment}
1865 When the error is raised, you must fill in the @code{value} and
1866 @code{comment} slots appropriately.
1867 @ecindex option-error
1868 @ecsindex{option-error,option}
1869 The super-condition @code{option-error} provides an additional
1870 @code{option} slot that you must also fill in when the error is raised.
1872 @gfmindex{check,@r{Enumerations (}enum@r{)}}
1873 @voindex{Enumerations,enum}
1874 @vopindex{Enumerations,enum,:enum}
1875 @findex list-to-string
1876 Let's look at the enumeration example now.
1878 @cartouche
1879 @verbatim
1880 (defmethod check ((enum enum) value)
1881   "Check that VALUE is a valid ENUM."
1882   (unless (member value (enum enum))
1883     (error 'invalid-value
1884            :option enum
1885            :value value
1886            :comment (format nil "Valid values are: ~A."
1887                       (list-to-string (enum enum)
1888                                       :key #'prin1-to-string))))
1889   value)
1890 @end verbatim
1891 @end cartouche
1893 This code should be self-explanatory. We check that the value we got
1894 belongs to the enumeration. @code{list-to-string} is a utility function
1895 that will separate every element with comas in the resulting string.
1897 @node Argument Conversion Protocol, Error Management, Value Check Protocol, New Option Types
1898 @subsection Argument Conversion Protocol
1899 @cindex Argument Conversion Protocol
1900 @cindex Protocols, argument conversion
1901 The next protocol we need to implement is the so-called @dfn{argument
1902 conversion} protocol. This protocol is used to convert option arguments
1903 (that is, strings) to an actual value of the proper type. Arguments
1904 going through this protocol come from the @cmdline{}, the value of an
1905 environment variable or a debugger restart (@pxenduserref{Error
1906 Management}). Also, note that @clon{} assumes that you implement this
1907 protocol correctly, so no value check is performed on values coming from
1908 the conversion of an argument.
1910 The conversion protocol is implemented through a @code{convert} generic
1911 function for which you must provide a method.
1913 @deffn {Generic Function} convert OPTION ARGUMENT
1914 @gfsubindex{convert}
1915 @ecindex invalid-argument
1916 Convert @var{ARGUMENT} to @var{OPTION's} value. If @var{ARGUMENT} is
1917 invalid, raise an @code{invalid-argument} error.
1918 @end deffn
1920 As you can see, you need to provide a method with the first argument
1921 specialized to your new option type. This method must return the
1922 conversion of @var{ARGUMENT} to the appropriate type if it is valid, and
1923 raise an @code{invalid-argument} error otherwise.
1925 @ecindex invalid-argument
1926 The @code{invalid-argument} error condition is defined like this:
1928 @cartouche
1929 @verbatim
1930 (define-condition invalid-argument (option-error)
1931   ((argument :documentation "The invalid argument."
1932              :type string
1933              :initarg :argument
1934              :reader argument)
1935    (comment :documentation "An additional comment about the error."
1936             :type string
1937             :initarg :comment
1938             :reader comment))
1939   (:report (lambda (error stream)
1940              (format stream "Option ~A: invalid argument ~S.~@[~%~A~]"
1941                (option error) (argument error) (comment error))))
1942   (:documentation "An invalid argument error."))
1943 @end verbatim
1944 @end cartouche
1946 @ecindex invalid-argument
1947 @ecsindex{invalid-argument,argument}
1948 @ecsindex{invalid-argument,comment}
1949 When the error is raised, you must fill in the @code{argument} and
1950 @code{comment} slots appropriately.
1951 @ecindex option-error
1952 @ecsindex{option-error,option}
1953 As before, the super-condition @code{option-error} provides an
1954 additional @code{option} slot that you must also fill in when the error
1955 is raised.
1957 @gfmindex{convert,@r{Enumerations (}enum@r{)}}
1958 @voindex{Enumerations,enum}
1959 @vopindex{Enumerations,enum,:enum}
1960 @findex closest-match
1961 Let's look at the enumeration example now.
1963 @cartouche
1964 @verbatim
1965 (defmethod convert ((enum enum) argument)
1966   "Convert ARGUMENT to an ENUM value."
1967   (or (closest-match argument (enum enum) :ignore-case t :key #'symbol-name)
1968       (error 'invalid-argument
1969              :option enum
1970              :argument argument
1971              :comment (format nil "Valid arguments are: ~A."
1972                         (list-to-string (enum enum)
1973                                         :key (lambda (value)
1974                                                (stringify enum value)))))))
1976 @end verbatim
1977 @end cartouche
1979 Since enumerations allow their arguments to be abbreviated, a utility
1980 function named @code{closest-match} is used to find the closest match
1981 between an argument and the possible values. Otherwise, an
1982 @code{invalid-argument} error is raised. For an explanation of
1983 @code{stringify}, @xref{Value Stringification Protocol}.
1985 @node Error Management, Value Stringification Protocol, Argument Conversion Protocol, New Option Types
1986 @subsection Error Management
1987 @cindex Debugger
1988 @cindex Debugger restarts
1989 Let's take a short break in our @clon{} extension process. We have seen
1990 that @clon{} may throw errors in different situations, including invalid
1991 arguments or values. The end-user manual advertises that the interactive
1992 error handler offers a set of ``options to fix problems'' (if you don't
1993 know what I'm talking about, please read @enduserref{Error Management}
1994 and you will know). Well, you may have guessed that these options are
1995 simply ``restarts'' (of course, we don't use that term there, as we
1996 wouldn't want to frighten the casual user, or would we?).
1998 When you ship your application, you are encouraged to disable the
1999 debugger in the standalone executable because that also might scare the
2000 casual user a little bit (the end-user manual only mentions the
2001 @code{none} error-handler to explain that people shouldn't use it). The
2002 way error handling is done in @cl{} standalone executables is
2003 implementation-dependent, so please refer to your favorite compiler's
2004 documentation. More generally, the behavior of @cl{} standalone
2005 executables may depend on:
2006 @itemize @bullet
2007 @item
2008 @cindex Dumping
2009 the state of the Lisp environment when the application was dumped, which
2010 may in turn depend on @cmdline{} options passed to the Lisp itself
2011 (@pxref{Dumping Executables}),
2012 @item
2013 @findex dump
2014 the arguments passed to the dumping function (look at @clon{}'s
2015 @code{dump} macro to see what it does),
2016 @item
2017 worse: @emph{both}.
2018 @end itemize
2020 No, really, @cl{} is no fun at all.
2022 @node Value Stringification Protocol, Constructor Functions, Error Management, New Option Types
2023 @subsection Value Stringification Protocol
2024 Okay, back to implementing our new option type.
2026 @cindex Value Stringification Protocol
2027 @cindex Protocols, value stringification
2028 The third and last protocol we need to implement is called the
2029 @dfn{value stringification} protocol. This protocol can be seen as the
2030 reverse protocol for argument conversion (@pxref{Argument Conversion
2031 Protocol}): its purpose is to transform an option's value into a
2032 corresponding argument that the end-user could have provided in order to
2033 get that value.
2035 @cindex Help String
2036 @cvopindex{:fallback-value}
2037 @cindex Values, source, fallback
2038 @cvopindex{:default-value}
2039 @cindex Values, source, default
2040 @gfmindex{convert,@r{Enumerations (}enum@r{)}}
2041 The main use for this protocol is to advertise the fallback and default
2042 values correctly in help strings: the end-user does not want to see
2043 those @emph{values}, but rather the @emph{argument} that would lead to
2044 them. However, you are free to use it wherever you like (see the
2045 @code{convert} method for @code{enum} options for instance).
2047 The value stringification protocol is implemented through a
2048 @code{stringify} generic function for which you must provide a method.
2050 @deffn {Generic Function} stringify OPTION VALUE
2051 @gfsubindex{stringify}
2052 Transform OPTION's @var{VALUE} into an argument.
2053 @end deffn
2055 I admit that this function could also have been called
2056 @code{argumentize} or even @code{deconvertify}. As you can see, you need
2057 to provide a method with the first argument specialized to your new
2058 option type. You can assume that @var{VALUE} is a valid value for your
2059 option, so no checking is necessary and no error needs to be raised.
2061 @gfmindex{stringify,@r{Enumerations (}enum@r{)}}
2062 @voindex{Enumerations,enum}
2063 Let's look at the enumeration example now.
2065 @cartouche
2066 @verbatim
2067 (defmethod stringify ((enum enum) value)
2068   "Transform ENUM's VALUE into an argument."
2069   (string-downcase (symbol-name value)))
2070 @end verbatim
2071 @end cartouche
2073 Pretty straightforward, right?
2076 @node Constructor Functions, , Value Stringification Protocol, New Option Types
2077 @subsection Constructor Functions
2078 @cindex Constructors, for options objects
2079 @cindex Option Constructors
2080 The last required step to complete our new option type extension is to
2081 provide a @dfn{constructor} function that wraps around
2082 @code{make-instance} on the corresponding option class. I won't insult
2083 you by explaining how to write a constructor. Let me just give four good
2084 reasons why providing constructors is important.
2086 Providing a constructor for every new option type is important because:
2087 @enumerate
2088 @item
2089 it is important,
2090 @item
2091 it is a good software engineering practice,
2092 @item
2093 it is important,
2094 @item
2095 @findex defsynopsis
2096 @findex defgroup
2097 and above all, it makes your new option type automatically available in
2098 calls to @code{defsynopsis} and @code{defgroup} (@pxref{Synopsis Items}
2099 and @ref{Group Definition}).
2100 @end enumerate
2103 @voindex{Enumerations,enum}
2104 @cfindex{make-enum}
2105 Let's look at the enumeration example now.
2107 @cartouche
2108 @verbatim
2109 (defun make-enum (&rest keys
2110                   &key short-name long-name description
2111                        argument-name argument-type
2112                        enum env-var fallback-value default-value
2113                        hidden)
2114   "Make a new enum option.
2115 - SHORT-NAME is the option's short name (without the dash).
2116   It defaults to nil.
2117 - LONG-NAME is the option's long name (without the double-dash).
2118   It defaults to nil.
2119 - DESCRIPTION is the option's description appearing in help strings.
2120   It defaults to nil.
2121 - ARGUMENT-NAME is the option's argument name appearing in help strings.
2122 - ARGUMENT-TYPE is one of :required, :mandatory or :optional (:required and
2123   :mandatory are synonyms).
2124   It defaults to :optional.
2125 - ENUM is the set of possible values.
2126 - ENV-VAR is the option's associated environment variable.
2127   It defaults to nil.
2128 - FALLBACK-VALUE is the option's fallback value (for missing optional
2129   arguments), if any.
2130 - DEFAULT-VALUE is the option's default value, if any.
2131 - When HIDDEN, the option doesn't appear in help strings."
2132   (declare (ignore short-name long-name description
2133                   argument-name argument-type
2134                   enum env-var fallback-value default-value
2135                   hidden))
2136   (apply #'make-instance 'enum keys))
2137 @end verbatim
2138 @end cartouche
2140 Woah, what a mouthful for a single line of code@dots{} Yeah, I'm a
2141 maniac and I like redundancy. I always restate all the available keys
2142 explicitely, and everything again in the docstring so that all the
2143 interesting information is directly available (I might change my mind as
2144 I grow older though).
2147 @c --------------
2148 @c Extension Tips
2149 @c --------------
2150 @node Extension Tips, , New Option Types, Extending Clon
2151 @section Extension Tips
2152 So that's it. Now you know how to extend @clon{} with your own option
2153 types. Here is some piece of advice that you might find useful in the
2154 process.
2156 @menu
2157 * Incremental Option Types::    Doing without defoption
2158 * Lisp Option Abuse::           Thinking in end-user terms
2159 @end menu
2161 @node Incremental Option Types, Lisp Option Abuse, Extension Tips, Extension Tips
2162 @subsection Incremental Option Types
2163 @findex defoption
2164 If one of the built-in options is almost what you need, you may be
2165 tempted to subclass it directly instead of using @code{defoption}, and
2166 only change what's needed, After all, it's Lisp. Lisp is a world of
2167 mess@t{^D^D^D^D}freedom.
2169 Wrong.
2171 @findex defsynopsis
2172 @findex defgroup
2173 @code{defoption} is not @emph{only} a convenience wrapper around
2174 @code{defclass}. It also arranges for @code{defsynopsis} and
2175 @code{defgroup} to recognize your new option type. So please, do use it
2176 systematically.
2178 @node Lisp Option Abuse, , Incremental Option Types, Extension Tips
2179 @subsection Lisp Option Abuse
2180 @voindex{Lisp Objects,lispobj}
2181 @vopindex{Lisp Objects,lispobj,:typespec}
2182 Along with the same lines, you may find that the @code{lispobj} type is
2183 all you need in many situations. Let's take an example. Suppose you want
2184 to implement a @code{--stars} option to assign a rank to a movie, from 0
2185 to 5. The lazy approach is to simply create a @code{lispobj} option with
2186 a @code{:typespec} (type specifier) of @code{(integer 0 5)} and you're
2187 done.
2189 But now, remember that the end-user of your application is probably not
2190 a Lisper (in fact, I would hope that @clon{} contributes to increasing
2191 the number of standalone @cl{} applications out there@dots{}). What do
2192 you think would be her reaction, if, after providing a bogus value to
2193 the @code{--stars} option, she get the following error message:
2195 @verbatim
2196  Option 'stars': invalid argument "6".
2197 Argument "6" must evaluate to (integer 0 5).
2198 @end verbatim
2200 or worse, a @code{"Cannot parse argument"} error message because of a
2201 typo?
2203 Not very friendly, right? In other words, you need to think in terms of
2204 what the end-user of your application will expect. In that particular
2205 situation, you might want to subclass @code{lispobj} (with
2206 @code{defoption}!) only to provide friendlier error messages.
2210 @c ====================================================================
2211 @c Advanced Usage
2212 @c ====================================================================
2213 @node Advanced Usage, Conclusion, Extending Clon, Top
2214 @chapter Advanced Usage
2216 This chapter contains information about different features that are
2217 present in @clon{} because of design decisions, but that I expect to be
2218 used only rarely, if at all.
2220 @menu
2221 * Multiple Clon Instances::     Different command-lines, synopsis or contexts
2222 * Programmatic Help Strings::   Beyond the --help option
2223 * Version Numbering::           In case you need to conditionalize
2224 @end menu
2227 @c -----------------------
2228 @c Multiple Clon Instances
2229 @c -----------------------
2230 @node Multiple Clon Instances, Programmatic Help Strings, Advanced Usage, Advanced Usage
2231 @section Multiple @clon{} Instances
2233 It is possible to use different instances of @clon{} in parallel in a
2234 single application, by using a virtual @cmdline{} instead of the real
2235 one, different synopsis and multiple contexts simultaneously.
2237 @menu
2238 * Using Different Synopsis::            The default one, and the others
2239 * Using Different Command-Lines::       The real one, and the others
2240 * Using Multiple Contexts::             The current one, and the others
2241 * Potential Uses::                      What to do with all that
2242 @end menu
2244 @node Using Different Synopsis, Using Different Command-Lines, Multiple Clon Instances, Multiple Clon Instances
2245 @subsection Using Different Synopsis
2246 @cindex Synopsis, default
2247 Did you notice that after defining a synopsis, there is actually never
2248 any explicit reference to it anymore? So where is the magick? In fact,
2249 there's no magick at all involved here.
2251 @vindex *synopsis*
2252 @foindex{defsynopsis,:make-default}
2253 @cfiaindex{make-synopsis,:make-default}
2254 @clon{} has a global variable named @code{*synopsis*} which holds the
2255 current synopsis. When you define/create a synopsis with either
2256 @code{defsynopsis} or @code{make-synopsis}, it is automatically made the
2257 default one, unless you use the @code{:make-default} option/initarg with
2258 a value of @code{nil}, like this:
2260 @verbatim
2261 (defsynopsis (:make-default nil) ...)
2262 @end verbatim
2264 or this:
2266 @verbatim
2267 (make-synopsis :make-default nil ...)
2268 @end verbatim
2270 @cfindex{make-context}
2271 When you create a context with @code{make-context}, the default synopsis
2272 is used implicitely, but you have two ways to avoid this.
2274 @enumerate
2275 @item
2276 @vindex *synopsis*
2277 At any time in your program, you may change the value of
2278 @code{*synopsis*}. All subsequent calls to @code{make-context} will
2279 hence use this other synopsis.
2280 @item
2281 @cfiaindex{make-context,:synopsis}@c
2282 If you prefer to use another synopsis only temporarily, you can use the
2283 @code{:synopsis} initarg to @code{make-context} instead.
2284 @end enumerate
2286 @node Using Different Command-Lines, Using Multiple Contexts, Using Different Synopsis, Multiple Clon Instances
2287 @subsection Using Different Command-Lines
2288 In @ref{Context Creation}, we saw that a context object describes a
2289 particular instance of your application, most notably depending on the
2290 actual @cmdline{} the end-user provided. It turns out, however that the
2291 @cmdline{} doesn't need to be the actual program's @cmdline{}, as the
2292 user typed it. Any list of strings can act as a @cmdline{}.
2294 @cfiaindex{make-context,:cmdline}
2295 The function @code{make-context} has a @code{:cmdline} key that allows
2296 you to provide any list of strings that will act as the @cmdline{}. Of
2297 course, the default is to use the actual program's one.
2299 @node Using Multiple Contexts, Potential Uses, Using Different Command-Lines, Multiple Clon Instances
2300 @subsection Using Multiple Contexts
2301 @cindex Context, current
2302 Did you also notice that after creating a context, there is actually
2303 never any explicit reference to it anymore? So again, where is the
2304 magick? In fact, there's no magick at all involved here either.
2306 @vindex *context*
2307 @cfiaindex{make-context,:make-current}@c
2308 @clon{} has a global variable named @code{*context*} which holds the
2309 current context. When you create a context with @code{make-context}, it
2310 is automatically made current, unless you use the @code{:make-current}
2311 initarg with a value of @code{nil}.
2313 @cindex Runtime Phase
2314 @findex progname
2315 @findex remainder
2316 @findex cmdline-options-p
2317 @findex cmdline-p
2318 @findex getopt
2319 @findex getopt-cmdline
2320 @findex multiple-value-getopt-cmdline
2321 @findex do-cmdline-options
2322 @findex help
2323 The whole runtime phase API of @clon{} uses a context implicitely. This
2324 involves @code{progname}, @code{remainder}, @code{cmdline-options-p},
2325 @code{cmdline-p}, @code{getopt}, @code{getopt-cmdline},
2326 @code{multiple-value-getopt-cmdline}, @code{do-cmdline-options} and
2327 @code{help}. As a consequence, it is possible to use @clon{} with
2328 multiple contexts at the same time. There are in fact three ways to
2329 achieve this.
2331 @enumerate
2332 @item
2333 @vindex *context*
2334 At any time in your program, you may change the value of
2335 @code{*context*}. All subsequent calls to the runtime phase API
2336 will hence use this other context.
2337 @item
2338 @clon{} also provides a macro which changes the current context for you.
2339 @defun with-context CONTEXT &body BODY
2340 Execute @var{BODY} with @code{*context*} bound to @var{CONTEXT}.
2341 @end defun
2342 @item
2343 @fkindex{progname,:context}@c
2344 @fkindex{remainder,:context}@c
2345 @fkindex{cmdline-options-p,:context}@c
2346 @fkindex{cmdline-p,:context}@c
2347 @fkindex{getopt,:context}@c
2348 @fkindex{getopt-cmdline,:context}@c
2349 @fkindex{help,:context}@c
2350 @foindex{multiple-value-getopt-cmdline,:context}@c
2351 @foindex{do-cmdline-options,:context}@c
2352 If you prefer to use another context only once, you can use the
2353 @code{:context} key instead. The whole runtime phase API of @clon{}
2354 understands it. For the functions @code{getopt}, @code{getopt-cmdline}
2355 and @code{help}, it's just another key in addition to those we've
2356 already seen. For the macros @code{multiple-value-getopt-cmdline} and
2357 @code{do-cmdline-options}, the key must appear at the end of the first
2358 (list) argument, like this:
2360 @verbatim
2361 (multiple-value-getopt-cmdline (option name value :context ctx) ...)
2362 (do-cmdline-options (option name value :context ctx) ...)
2363 @end verbatim
2364 @end enumerate
2366 @node Potential Uses, , Using Multiple Contexts, Multiple Clon Instances
2367 @subsection Potential Uses
2368 By combining @clon{}'s ability to use a virtual @cmdline{}, different
2369 synopsis and multiple contexts, you can achieve very neat (read: totally
2370 useless) things. For instance, you could write an application that takes
2371 an option providing @cmdline{} arguments for an external program to be
2372 forked. Some revision control systems do that for controlling external
2373 @code{diff} programs for instance, so no big deal. The big deal is that
2374 you can completely control the validity of the external program's
2375 @cmdline{}, before it is forked, from your original one.
2377 Here is another idea, again related to revision control systems. Some of
2378 them feature a @cmdline{} syntax like the following:
2380 @verbatim
2381 prog [global options] command [command-specific options]
2382 @end verbatim
2384 @cindex Postfix
2385 @cindex Command-Line, remainder
2386 @cindex Remainder, of command-line
2387 You can achieve this with @clon{} quite easily. In fact, the
2388 demonstration program called @file{advanced} in the distribution shows
2389 you how to do it. First, define a synopsis which only handles the global
2390 options, and provide a postfix of @code{"command [command-specific
2391 option]"} or something like that. This will authorize a @cmdline{}
2392 remainder which will start with the command name.
2394 Now, for every command in your program, define a specific synopsis with
2395 only the command-specific options. Get the remainder of the original
2396 @cmdline{} (@pxref{Command-Line Remainder}) and figure out which command
2397 was used. Depending on it, create a new context with the appropriate
2398 synopsis and the original @cmdline{}'s remainder as the new, virtual,
2399 @cmdline{}. You're done: retrieve global options from the first context,
2400 and command-specific ones from the second one.
2402 @cindex Help String, display
2403 @findex help
2404 What's even cooler is that you can display the command-specific options
2405 on demand quite easily as well (like what @file{git} does when you call
2406 it like this: @code{git commit --help} for instance): calling the
2407 @code{help} function on the original context gives you the global
2408 options's help string while calling it on the command-specific one will
2409 display the command-specific usage.
2411 @bioindex{search-path}
2412 @bievindex{SEARCH_PATH}
2413 @bioindex{highlight}
2414 @bievindex{HIGHLIGHT}
2415 @bioindex{theme}
2416 @bievindex{THEME}
2417 @bioindex{line-width}
2418 @bievindex{LINE_WIDTH}
2419 One thing to remember here is that every context/synopsis duet you
2420 create gets its own set of built-in @clon{} options. As a consequence,
2421 there is currently no simple way to have a single set of built-in
2422 options apply to the whole application, for instance, to both a global
2423 and a command-specific context. Let me make this clearer: if your
2424 end-user calls @code{prog --clon-theme=foo command -h}, then the theme
2425 option will have no effect because it would only affect the global help
2426 option. In order to actually use the expected theme, your end-user would
2427 need to use @code{prog command --clon-theme=foo -h}. Depending on which
2428 cerebral emisphere (s)he prefers to use, this may seem logical or not.
2430 Finally, note that you can use the virtual @cmdline{} / specific
2431 synopsis technique recursively to manage complicated @cmdline{} syntax,
2432 for instance alternating options and non-options parts several times.
2434 In the future, @clon{} may provide better ways to achieve this kind of
2435 things (a notion of ``sub-context'' may be in order).
2439 @c -------------------------
2440 @c Programmatic Help Strings
2441 @c -------------------------
2442 @node Programmatic Help Strings, Version Numbering, Multiple Clon Instances, Advanced Usage
2443 @section Programmatic Help Strings
2445 @findex help
2446 @cindex Help String
2447 @cindex Themes
2448 @cindex Themes, standard, @t{refcard}
2449 @cindex Standard Themes, @t{refcard}
2450 So far, we've seen how to use the @code{help} function to implement a
2451 typical @code{--help} option. This is mostly intended for the end-user.
2452 There are also times when this function could be useful to @emph{you},
2453 the application developer. For instance, one could imagine that part of
2454 the compilation phase would involve generating the help string in order
2455 to include it in the manual. Another idea would be that @samp{make
2456 install} creates a @file{REFCARD} file in
2457 @file{/usr/local/share/doc/my-app/} which contains the help string
2458 formatted with the @code{refcard} theme, @etc{}.
2460 @bioindex{theme}
2461 @bievindex{THEME}
2462 @bioindex{search-path}
2463 @bievindex{SEARCH_PATH}
2464 @bioindex{line-width}
2465 @bievindex{LINE_WIDTH}
2466 @bioindex{highlight}
2467 @bievindex{HIGHLIGHT}
2468 In such situations, calling the @code{help} function might not be
2469 directly associated with an end-user level option, or at least not
2470 @code{--help}, and you might not want to honor the end-user level
2471 settings for theme, search path, line-width, or highlighting either
2472 (remember that these settings might come from the environment variables
2473 associated with @bioption{theme}, @bioption{search-path},
2474 @bioption{line-width} and @bioption{highlight}).
2476 @fkindex{help,:theme}
2477 @fkindex{help,:search-path}
2478 @fkindex{help,:line-width}
2479 @fkindex{help,:highlight}
2480 Because of this, the @code{help} function provides additional keys that
2481 allow you to override those settings (they are in fact stored in the
2482 context object). The keys in question are: @code{:theme},
2483 @code{:search-path}, @code{:line-width} and @code{:highlight}.
2485 @fkindex{help,:output-stream}
2486 @vindex *standard-output*
2487 In addition to that, there is an @code{:output-stream} key which
2488 defaults to @code{*standard-output*} which you could use for instance to
2489 write directly to a file. Note that there is no end-user level access to
2490 this parameter.
2494 @c -----------------
2495 @c Version Numbering
2496 @c -----------------
2497 @node Version Numbering, , Programmatic Help Strings, Advanced Usage
2498 @section Version Numbering
2500 @bioindex{version}
2501 As @clon{} evolves over time, you might one day feel the need for
2502 conditionalizing your code on the version of the library. While the
2503 end-user of your application has limited means to access the current
2504 version number of @clon{} (see @enduserref{Clonification} and the
2505 built-in option @bioption{version}), you, the application programmer
2506 and @clon{} user, have a finer grained access to it.
2508 The first thing you can do to access the current version number of
2509 @clon{} is use the @code{version} function (this is in fact the function
2510 bound to the @bioption{version} option).
2512 @defun version &optional (TYPE :number)
2513 Return the current version number of @clon{}. @var{TYPE} can be one of
2514 @code{:number}, @code{:short} or @code{:long}. For @code{:number}, the
2515 returned value is a fixnum. Otherwise, it is a string.
2516 @end defun
2518 A @clon{} version is characterized by 4 elements as described below.
2519 @itemize
2520 @item
2521 @vindex +release-major-level+
2522 A major version number stored in the constant
2523 @code{+release-major-level+}.
2524 @item
2525 @vindex +release-minor-level+
2526 A minor version number, stored in the constant
2527 @code{+release-minor-level+}.
2528 @item
2529 @vindex +release-status+
2530 A release status stored in the constant @code{+release-status+}. The
2531 status of a release can be @code{:alpha}, @code{:beta}, @code{:rc}
2532 (standing for ``release candidate'') or @code{:patchlevel}. These are in
2533 effect 4 levels of expected stability.
2534 @item
2535 @vindex +release-status-level+
2536 A status-specific version number stored in the constant
2537 @code{+release-status-level+}. Status levels start at 1 (alpha 1, beta 1
2538 and release candidate 1) except for stable versions, in which case patch
2539 levels start at 0 (@eg{} 2.4.0).
2540 @end itemize
2542 @vindex +release-name+
2543 In addition to that, each version of @clon{} (in the sense
2544 @emph{major.minor}, regardless of the status) has a name, stored in the
2545 constant @code{+release-name+}. The general theme for @clon{} is ``Great
2546 Jazz Musicians'', and specifically for the 1.x series: ``Great Saxophone
2547 Players''. Anyone daring to mention Kenny G at that point will be shot
2548 on sight.
2550 Here is how the @code{version} function computes its value.
2551 @itemize
2552 @item
2553 A version @code{:number} is computed as @emph{major . 10000 + minor .
2554 100 + patchlevel}, effectively leaving two digits for each level. Note
2555 that alpha, beta and release candidate status are ignored in version
2556 numbers (this is as if the corresponding status level was considered to
2557 be always 0). Only stable releases have their level taken into account.
2558 @item
2559 A @code{:short} version will appear like this for unstable releases:
2560 1.3a4, 2.5b8 or 4.2rc1. Remember that alpha, beta or release candidate
2561 levels start at 1. Patchlevels for stable releases start at 0 but 0 is
2562 ignored in the output. So for instance, version 4.3.2 will appear as-is,
2563 while version 1.3.0 will appear as just 1.3.
2564 @item
2565 A @code{:long} version is expanded from the short one, and includes the
2566 release name. For instance, 1.3 alpha 4 "Bill Evans", 2.5 beta 8 "Scott
2567 Henderson", 4.2 release candidate 1 "Herbie Hancock" or 4.3.2 "Chick
2568 Corea". As for the short version, a patchlevel of 0 is ignored in the
2569 output: 1.3 "Bill Evans".
2570 @end itemize
2574 @c ====================================================================
2575 @c Conclusion
2576 @c ====================================================================
2577 @node Conclusion, Technical Notes, Advanced Usage, Top
2578 @chapter Conclusion
2580 So that's it I guess. You know all about @clon{} now. The next step is
2581 to actually use it to clonify your favorite application, write new
2582 applications using it and contaminate the world with standalone @cl{}
2583 programs, featuring unprecedented @cmdline{} power and thrill-a-minute
2584 option hacking.
2586 Now, go Luke. The Attack of the @clon{} is ready to begin.
2590 @c ====================================================================
2591 @c Technical Notes
2592 @c ====================================================================
2593 @node Technical Notes, API Quick Reference, Conclusion, Top
2594 @appendix Technical Notes
2596 This chapter contains important information about the library's
2597 configuration, supported platforms, non-ANSI features and
2598 portability concerns.
2600 @menu
2601 * Configuration::               Pre-loading parameters
2602 * Non-ANSI Features::           Requiring operating system access
2603 * Supported Platforms::         Systems, compilers and dependencies
2604 * Dumping Executables::         Convenience wrappers
2605 * Not Dumping Executables::     Using Clon interactively
2606 @end menu
2609 @c -------------
2610 @c Configuration
2611 @c -------------
2612 @node Configuration, Non-ANSI Features, Technical Notes, Technical Notes
2613 @section Configuration
2614 @cindex Configuration
2615 @vindex com.dvlsoft.clon.configuration
2616 Some aspects of @clon{}'s behavior can be configured @emph{before} the
2617 ASDF system is actually loaded. @clon{} looks for configuration options
2618 in a variable called @code{com.dvlsoft.clon.configuration} in the
2619 @code{cl-user} package. If set, this variable should contain a property
2620 list of configuration options and their corresponding values. Currently,
2621 the following options are provided.
2623 @table @t
2624 @item :swank-eval-in-emacs
2625 @coindex{swank-eval-in-emacs}@c
2626 @vindex slime-enable-evaluate-in-emacs
2627 This option is only useful if you use Slime, and mostly if you plan on
2628 hacking @clon{} itself. The library provides indentation information for
2629 some of its functions directly embedded in the code. This information
2630 can be automatically transmitted to (X)Emacs when the ASDF system is
2631 loaded if you set this option to @code{t}. However, note that for this
2632 to work, the Slime variable @code{slime-enable-evaluate-in-emacs} must
2633 also be set to @code{t} in your (X)Emacs session. If you're interested
2634 to know how this process works, I have described it in the following
2635 blog entry:
2636 @uref{http://www.didierverna.com/sciblog/index.php?post/2011/07/20/One-more-indentation-hack}.
2637 @item :restricted
2638 @coindex{restricted}@c
2639 @cindex Restricted Mode
2640 Some non-ANSI features of @clon{} require external functionality that
2641 may not be available in all contexts. Normally, @clon{} should
2642 autodetect this and switch to so-called @emph{restricted mode} at
2643 build-time (@pxref{Non-ANSI Features}). If @clon{} has failed to
2644 autodetect the problem (in which case I would like to know), or if for
2645 some reason, you explicitly want to disable those features, you may set
2646 the @code{:restricted} configuration option to @code{t}.
2647 @item :dump
2648 @coindex{dump}@c
2649 This option is only used by the ABCL port. @ref{Dumping Executables},
2650 provides more information on its use.
2651 @end table
2654 @c -----------------
2655 @c Non-ANSI Features
2656 @c -----------------
2657 @node Non-ANSI Features, Supported Platforms, Configuration, Technical Notes
2658 @section Non-ANSI Features
2659 One feature of @clon{} that is beyond the ANSI standard is terminal
2660 autodetection (it requires an @code{ioctl} call and hence a foreign
2661 function interface). Terminal autodetection is used in several
2662 situations, for turning on highlighting automatically and for detecting
2663 a terminal line width.
2665 @cindex Restricted Mode
2666 If, for some reason, terminal autodetection is not available, @clon{}
2667 will work in so-called @emph{restricted mode}. This means that
2668 @bioption{highlight=auto} won't work (highlighting will @emph{not} be
2669 turned on automatically on a @tty{}). For the same reason, unless
2670 otherwise specified via either the @code{COLUMNS} environment variable
2671 or the @bioption{line-width} option, terminal output will be formatted
2672 for 80 columns regardless of the actual terminal width
2673 (@pxenduserref{Global Control}).
2676 @c ----------------------
2677 @c Supported Platforms
2678 @c ----------------------
2679 @node Supported Platforms, Dumping Executables, Non-ANSI Features, Technical Notes
2680 @section Supported Platforms
2681 @clon{} currently works on Unix (including MacOS X) and Windows (Cygwin
2682 or MinGW) and has been ported to 8 @cl{} implementations. The following
2683 table lists the supported platforms.
2685 @multitable {Compiler} {Minimum Version} {@code{cffi} (optional)}
2686 @headitem Compiler @tab Minimum Version @tab Dependencies
2687 @item SBCL
2688 @tab 1.0.56
2689 @tab
2690 @item CMU-CL
2691 @tab 20b
2692 @tab
2693 @item CCL
2694 @tab
2695 @tab
2696 @item ECL
2697 @tab 11.1.2@footnote{more precisely, git revision
2698 3e2e5f9dc3c5176ef6ef8d7794bfa43f1af8f8db}
2699 @tab
2700 @item CLISP
2701 @tab
2702 @tab @code{cffi} (optional)
2703 @item ABCL
2704 @tab 1.1.0@footnote{more precisely, svn trunk revision 140640}
2705 @tab
2706 @item Allegro@footnote{both standard and modern images are supported}
2707 @tab
2708 @tab @code{cffi} (optional)
2709 @item LispWorks
2710 @tab
2711 @tab @code{cffi} (optional)
2712 @end multitable
2714 @unnumberedsubsec CLISP, Allegro and LispWorks specificities
2715 @cindex Restricted Mode
2716 As mentioned in the above table, CLISP, Allegro and LispWorks dependency
2717 on @code{cffi} is optional. They need @code{cffi} in order to implement
2718 terminal autodetection only (note that many other implementations come
2719 with their own foreign function interface). If @code{cffi} cannot be
2720 found when the ASDF system is loaded (or in the case of CLISP, if it has
2721 been compiled without @code{ffi} support), you get a big red blinking
2722 light and a warning but that's all. @clon{} will still work, although in
2723 restricted mode.
2725 @unnumberedsubsec ABCL specificities
2726 @clon{}'s ABCL port currently has two limitations:
2727 @itemize @bullet
2728 @item
2729 @bioindex{highlight}@c
2730 @bioindex{line-width}@c
2731 @evindex{COLUMNS}@c
2732 @cindex Restricted Mode
2733 It only works in restricted mode (@pxref{Non-ANSI Features}).
2734 @item
2735 Since Java doesn't have a @code{putenv} or @code{setenv} function (!!),
2736 the @code{modify-environment} restart, normally proposed when an
2737 environment variable is set to a bogus value, is unavailable
2738 (@pxenduserref{Error Management}).
2739 @end itemize
2742 @c -------------------
2743 @c Dumping Executables
2744 @c -------------------
2745 @node Dumping Executables, Not Dumping Executables, Supported Platforms, Technical Notes
2746 @section Dumping Executables
2747 @cindex Dumping
2748 Creating standalone executables is orthogonal to @clon{}. @clon{} is
2749 just a library that you might want to use, and in fact, it is also
2750 possible to use it without dumping executables at all (@pxref{Not
2751 Dumping Executables}).
2753 @findex exit
2754 @findex dump
2755 Unfortunately, there is no standard way to dump executables from Lisp.
2756 We're entering the portability mine field here. @clon{}, however, wants
2757 to help. We've already seen that it provides utility wrappers like
2758 @code{exit} and @code{dump} to make your life easier (I mean, more
2759 portable) in @ref{Quick Start}. If you're not interested in portability
2760 or if you prefer to do it your own way, you don't @emph{need} to use
2761 those wrappers. If you do, however, please read on.
2763 Continuing on the quickstart example, the table below provides
2764 ready-to-use @cmdline{} samples for dumping the program with the
2765 compilers currently supported. Remember that they work in conjunction
2766 with the somewhat rudimentary @code{dump} macro mentionned above.
2768 @table @strong
2769 @item SBCL
2770 @code{CC=gcc sbcl --script quickstart.lisp}@*
2771 The @code{CC=gcc} bit is needed for the @code{sb-grovel} contrib module
2772 that @clon{} uses (unless restricted mode is requested).
2773 @item CMUCL
2774 @code{lisp -noinit -nositeinit -load quickstart.lisp}
2775 @item CCL
2776 @code{ccl --no-init --load quickstart.lisp}
2777 @item ECL
2778 ECL doesn't work like the other Lisp compilers. In particular, creating
2779 an executable does not involve dumping a Lisp image, but compiling the
2780 source into separate object files and then linking them. The consequence
2781 is that there is no simple @cmdline{} recipe to show here. Instead, you
2782 might want to look at the file @file{demos/dump.lisp} in the
2783 distribution for an example. Note that this file doesn't really attempt
2784 to dump the whole application. Only the actual example file is dumped.
2786 Because the dumping scheme is different with ECL, it is also less
2787 straightforward to write portable code for standalone applications. The
2788 demo programs in the distribution both contain comments that are worth
2789 reading at the top of them.
2791 @findex dump
2792 One specific difference between ECL and the other Lisp compilers is that
2793 it doesn't require you to specify a particular function as the entry
2794 point for your executable, but instead relies on having code to execute
2795 directly at the toplevel of some file. @clon{}'s @code{dump} macro helps
2796 you with this: it normally expands to a compiler-specific function which
2797 saves the current Lisp image, but for ECL, it simply expands to the
2798 ``main'' function call, hence consituting the entry point to the code
2799 that ECL needs.
2800 @item CLISP
2801 @code{CC=gcc clisp -norc -i quickstart.lisp}@*
2802 The @code{CC=gcc} bit lets you choose your preferred C compiler for
2803 @code{cffi}. Please note that executables dumped (the @clon{} way) by
2804 CLISP still understand lisp-specific @cmdline{} options when they are
2805 prefixed with @code{--clisp-}, so you should obviously avoid defining
2806 options by those names.
2807 @item ABCL
2808 ABCL is a totally different beast because it's a Java-based @cl{}
2809 implementation. Most notably, you don't create standalone executables in
2810 Java, so the normal way of running ABCL is by telling it to load some
2811 lisp code. If you want to run the quickstart program in the usual way,
2812 you will typically type this:
2813 @verbatim
2814 abcl --noinform --noinit --nosystem --load quickstart.lisp
2815 @end verbatim
2816 Note that for this to work, the @code{dump} macro expands to the
2817 ``main'' function call for ABCL, just as for ECL.
2819 There's more to it than that though. It is possible to get closer to
2820 standalone executables with ABCL by 1/ providing your whole application
2821 in a @code{jar} file directly, and 2/ overriding ABCL's entry point by
2822 providing your own interpreter which runs your main function
2823 automatically. I have described this process in more details in the
2824 following blog entry:
2825 @uref{http://www.didierverna.com/sciblog/index.php?post/2011/01/22/Towards-ABCL-Standalone-Executables}.
2827 @coindex{dump}@c
2828 @clon{} helps you to do this to some extend. If the @code{:dump}
2829 configuration option is set (@pxref{Configuration}), then the
2830 @code{dump} macro doesn't expand to a call to the ``main'' function, but
2831 instead dumps a Java file containing an alternate ABCL interpreter that
2832 you can compile and add to the original ABCL @code{jar} file, along with
2833 @file{quickstart.lisp}. If you want more details on this, you will need
2834 to look at the @file{Makefile} in the @code{demo} directory and also at
2835 the file @file{Makefile.inc} at the toplevel.
2836 @item Allegro
2837 @findex dumplisp
2838 Dumping a complete application with Allegro is complicated, but more
2839 importantly only possible in the Enterprise edition. Because of that,
2840 @clon{}'s dumping facility only makes use of the @code{dumplisp} feature
2841 which just dumps a Lisp image. You can perform this operation with a
2842 @cmdline{} such as @samp{alisp -qq -L quickstart.lisp}. The Makefile
2843 infrastructure in the @file{demo} directory also creates shell script
2844 wrappers around this image to simplify their use.
2845 @item LispWorks
2846 @code{lispworks -init - -siteinit - -load quickstart.lisp}@*
2847 Please note that dumping a complete application with LispWorks is only
2848 possible in the Professional or Enterprise editions.
2849 @end table
2852 @c -----------------------
2853 @c Not Dumping Executables
2854 @c -----------------------
2855 @node Not Dumping Executables, , Dumping Executables, Technical Notes
2856 @section Not Dumping Executables
2857 Although @cmdline{} processing really makes sense for standalone
2858 executables, you may want to preserve interactivity with your
2859 application during the development phase, for instance for testing or
2860 debugging purposes.
2862 It is possible to use @clon{} interactively, that is, within a regular
2863 Lisp REPL, without dumping anything. First of all, we have already seen
2864 that it is possible to use a virtual @cmdline{} (@pxref{Using Different
2865 Command-Lines}). You can also use @clon{} interactively with the actual
2866 Lisp invocation's @cmdline{}, although a word of advice is in order
2867 here.
2869 @findex cmdline
2870 @findex dump
2871 As you might expect, the problem in that situation lies in the way the
2872 different Lisp implementations treat their own @cmdline{}. Guess what,
2873 it's a mess. When you dump an executable the @clon{} way, the
2874 @code{cmdline} function will always contain user options only (the
2875 @code{dump} macro instructs the compilers to @emph{not} process the
2876 @cmdline{} at all). When you use @clon{} interactively and mix
2877 compiler-specific options with application ones when invoking your Lisp
2878 environment, the situation is as follows:
2880 @table @strong
2881 @item SBCL
2882 SBCL processes its own options and leaves the others unprocessed on the
2883 @cmdline{}. This means that as long as there is no overlap between
2884 SBCL's options and yours, you can just put them all together on the
2885 @cmdline{}. In case of overlap however, you need to separate SBCL's
2886 options from yours with a call to @code{--end-toplevel-options} (that's
2887 an SBCL specific option separator).
2888 @item CMUCL
2889 @cindex Command-Line, remainder
2890 @cindex Remainder, of command-line
2891 CMUCL processes its own options, issues a warning about the options it
2892 doesn't know about, but in any case, it eats the whole @cmdline{}.
2893 Consequently, if you want to provide options to your application, you
2894 need to put them after a @code{--} separator. Note that you can still
2895 use a second such separator to provide @clon{} with both some options
2896 and a remainder (@pxenduserref{Option Separator}).
2897 @item CCL
2898 @itemx ECL
2899 @itemx CLISP
2900 CCL, ECL and CLISP all process their own options but will abort on
2901 unknown ones. Consequently, if you want to provide options to your
2902 application, you need to put them after a @code{--} separator. Note that
2903 you can still use a second such separator to provide @clon{} with both
2904 some options and a remainder (@pxenduserref{Option Separator}).
2905 @item ABCL
2906 ABCL processes its own options and leaves the others unprocessed on the
2907 @cmdline{}. This means that as long as there is no overlap between
2908 ABCL's options and yours, you can just put them all together on the
2909 @cmdline{}. In case of overlap however, you need to separate ABCL's
2910 options from yours with a @code{--} separator. Note that you can still
2911 use a second such separator to provide @clon{} with both some options
2912 and a remainder (@pxenduserref{Option Separator}).
2913 @item Allegro
2914 Allegro processes its own options, issues only a warning about options
2915 it doesn't know of, and leaves anything after a @code{--} alone.
2916 Consequently, if you want to provide options to your application, you
2917 need to put them after a @code{--} separator. Note that you can still
2918 use a second such separator to provide @clon{} with both some options
2919 and a remainder (@pxenduserref{Option Separator}).
2920 @item LispWorks
2921 LispWorks processes its own options and ignores the other ones, but
2922 always leaves everything on the command-line. It does not currently
2923 support @code{--} as an option separator either. Consequently, if you
2924 want to provide options to your application, you need to put them after
2925 a @code{--} separator, although you @emph{will} get into trouble if any
2926 option there is recognized by LispWorks itself. Note that you can still
2927 use a second such separator to provide @clon{} with both some options
2928 and a remainder (@pxenduserref{Option Separator}).
2929 @end table
2933 @c ====================================================================
2934 @c API Quick Reference
2935 @c ====================================================================
2936 @node API Quick Reference, Indexes, Technical Notes, Top
2937 @appendix API Quick Reference
2939 @menu
2940 * Utilities::                   Miscellaneous stuff
2941 * Initialization Phase API::    Synopsis, items and context creation
2942 * Runtime Phase API::           Option retrieval and help formatting
2943 * Extension API::               New option types
2944 * Versioning API::              Release identification
2945 @end menu
2948 @c ---------
2949 @c Utilities
2950 @c ---------
2951 @node Utilities, Initialization Phase API, API Quick Reference, API Quick Reference
2952 @section Utilities
2954 @defmac dump NAME FUNCTION &rest ARGS
2955 See @ref{Quick Start}.
2956 @end defmac
2958 @defun exit &optional (STATUS 0)
2959 See @ref{Quick Start}.
2960 @end defun
2962 @cindex Command-Line
2963 @defun cmdline
2964 See @ref{Option Retrieval}.
2965 @end defun
2967 @cindex Package, nicknames
2968 @defun nickname-package &optional NICKNAME
2969 See @ref{Quick Start}.
2970 @end defun
2973 @c ------------------------
2974 @c Initialization Phase API
2975 @c ------------------------
2976 @node Initialization Phase API, Runtime Phase API, Utilities, API Quick Reference
2977 @section Initialization Phase API
2979 @defun make-text &key CONTENTS HIDDEN
2980 @cfsubindex{make-text}
2981 @cfiaindex{make-text,:contents}
2982 @cfiaindex{make-text,:hidden}
2983 @defunx make-@var{OPTION} :INITARG INITVAL@dots{}
2984 @cfsubindex{make-@var{OPTION}}
2985 @cfindex make-flag
2986 @cfindex make-stropt
2987 @cfindex make-lispobj
2988 @cfindex make-enum
2989 @cfindex make-path
2990 @cfindex make-switch
2991 @cfindex make-xswitch
2992 @defunx make-group &key HEADER HIDDEN ITEM
2993 @cfsubindex{make-group}
2994 @cfiaindex{make-group,:header}
2995 @cfiaindex{make-group,:hidden}
2996 @cfiaindex{make-group,:item}
2997 @defunx make-synopsis &key POSTFIX ITEM (MAKE-DEFAULT t)
2998 @cfsubindex{make-synopsis}
2999 @cfiaindex{make-synopsis,:postfix}
3000 @cfiaindex{make-synopsis,:item}
3001 @cfiaindex{make-synopsis,:make-default}
3002 See @ref{Constructors} and @ref{Using Different Synopsis}.
3003 @end defun
3005 @defmac defgroup (&key HEADER HIDDEN) &body FORMS
3006 @foindex{defgroup,:header}
3007 @foindex{defgroup,:hidden}
3008 @xref{Group Definition}.
3009 @end defmac
3011 @defmac defsynopsis (&key POSTFIX MAKE-DEFAULT) &body FORMS
3012 @foindex{defsynopsis,:postfix}
3013 @foindex{defsynopsis,:make-default}
3014 @fiindex{defsynopsis,text}
3015 @fiindex{defsynopsis,options}
3016 @fiindex{defsynopsis,group}
3017 See @ref{Synopsis Definition} and @ref{Using Different Synopsis}.
3018 @end defmac
3020 @defopt *synopsis*
3021 @xref{Using Different Synopsis}.
3022 @end defopt
3024 @defun make-context &key (SYNOPSIS *synopsis*) CMDLINE @
3025 (MAKE-CURRENT t)
3026 @cfsubindex{make-context}
3027 @cfiaindex{make-context,:synopsis}
3028 @cfiaindex{make-context,:cmdline}
3029 @cfiaindex{make-context,:make-current}
3030 @xref{Context Creation}, @ref{Using Different Synopsis} and @ref{Using
3031 Different Command-Lines}.
3032 @end defun
3036 @c -----------------
3037 @c Runtime Phase API
3038 @c -----------------
3039 @node Runtime Phase API, Extension API, Initialization Phase API, API Quick Reference
3040 @section Runtime Phase API
3042 @defopt *context*
3043 @xref{Using Multiple Contexts}.
3044 @end defopt
3046 @defun with-context CONTEXT &body BODY
3047 @xref{Using Multiple Contexts}.
3048 @end defun
3050 @defun progname &key (CONTEXT *context*)
3051 @fkindex{progname,:context}
3052 See @ref{Contextual Information} and @ref{Using Multiple Contexts}.
3053 @end defun
3055 @defun remainder &key (CONTEXT *context*)
3056 @fkindex{remainder,:context}
3057 See @ref{Contextual Information} and @ref{Using Multiple Contexts}.
3058 @end defun
3060 @defun cmdline-options-p &key (CONTEXT *context*)
3061 @fkindex{cmdline-options-p,:context}
3062 See @ref{Command-Line Polling} and @ref{Using Multiple Contexts}.
3063 @end defun
3065 @defun cmdline-p &key (CONTEXT *context*)
3066 @fkindex{cmdline-p,:context}
3067 See @ref{Command-Line Polling} and @ref{Using Multiple Contexts}.
3068 @end defun
3070 @defun getopt &key (CONTEXT *context*) SHORT-NAME LONG-NAME @
3071 OPTION
3072 @fkindex{getopt,:context}
3073 @fkindex{getopt,:short-name}
3074 @fkindex{getopt,:long-name}
3075 @fkindex{getopt,:option}
3076 @vindex *context*
3077 See @ref{Explicit Retrieval} and @ref{Using Multiple Contexts}.
3078 @end defun
3080 @defun getopt-cmdline &key (CONTEXT *context*)
3081 @fkindex{getopt-cmdline,:context}
3082 @vindex *context*
3083 See @ref{Sequential Retrieval} and @ref{Using Multiple Contexts}.
3084 @end defun
3086 @defmac multiple-value-getopt-cmdline (OPTION NAME VALUE SOURCE &key CONTEXT) @
3087 &body BODY
3088 @defmacx do-cmdline-options (OPTION NAME VALUE SOURCE &key CONTEXT) @
3089 &body BODY
3090 @foindex{multiple-value-getopt-cmdline,:context}
3091 @foindex{do-cmdline-options,:context}
3092 See @ref{Sequential Retrieval} and @ref{Using Multiple Contexts}.
3093 @end defmac
3095 @deffn Reader short-name OPTION
3096 @rfsubindex{short-name}
3097 @deffnx Reader long-name OPTION
3098 @rfsubindex long-name
3099 @xref{Sequential Retrieval}.
3100 @end deffn
3102 @defun help &key (CONTEXT *context*) @
3103 (ITEM (synopsis context)) @
3104 (OUTPUT-STREAM *standard-output*) @
3105 (SEARCH-PATH (search-path context)) @
3106 (THEME (theme context)) @
3107 (LINE-WIDTH (line-width context)) @
3108 (HIGHLIGHT (highlight context)))
3109 @fkindex{help,:context}
3110 @fkindex{help,:item}
3111 @fkindex{help,:output-stream}
3112 @fkindex{help,:theme}
3113 @fkindex{help,:search-path}
3114 @fkindex{help,:line-width}
3115 @fkindex{help,:highlight}
3116 @vindex *context*
3117 @vindex *standard-output*
3118 @xref{Help}, @ref{Using Multiple Contexts} and @ref{Programmatic Help
3119 Strings}.
3120 @end defun
3123 @c -------------
3124 @c Extension API
3125 @c -------------
3126 @node Extension API, Versioning API, Runtime Phase API, API Quick Reference
3127 @section Extension API
3129 @defmac defoption CLASS SUPERCLASSES SLOTS &rest OPTIONS
3130 @pxref{New Option Classes}
3131 @end defmac
3133 @deffn {Generic Function} check OPTION VALUE
3134 @gfsubindex{check}
3135 @xref{Value Check Protocol}.
3136 @end deffn
3138 @deftp {Error Condition} option-error OPTION
3139 @ecsubindex{option-error}
3140 @ecsindex{option-error,option}
3141 @deftpx {Error Condition} invalid-value VALUE COMMENT
3142 @ecsubindex{invalid-value}
3143 @ecsindex{invalid-value,value}
3144 @ecsindex{invalid-value,comment}
3145 @xref{Value Check Protocol}.
3146 @end deftp
3148 @deffn {Generic Function} convert OPTION ARGUMENT
3149 @gfsubindex{convert}
3150 @xref{Argument Conversion Protocol}.
3151 @end deffn
3153 @deftp {Error Condition} invalid-argument ARGUMENT COMMENT
3154 @ecsubindex{invalid-argument}
3155 @ecsindex{invalid-argument,argument}
3156 @ecsindex{invalid-argument,comment}
3157 @xref{Argument Conversion Protocol}.
3158 @end deftp
3160 @deffn {Generic Function} stringify OPTION VALUE
3161 @gfsubindex{stringify}
3162 @xref{Value Stringification Protocol}.
3163 @end deffn
3166 @c --------------
3167 @c Versioning API
3168 @c --------------
3169 @node Versioning API, , Extension API, API Quick Reference
3170 @section Versioning API
3172 @defun version &optional (TYPE :number)
3173 @xref{Version Numbering}.
3174 @end defun
3176 @defvr Constant +release-major-level+
3177 @defvrx Constant +release-minor-level+
3178 @defvrx Constant +release-status+
3179 @defvrx Constant +release-status-level+
3180 @defvrx Constant +release-name+
3181 @xref{Version Numbering}.
3182 @end defvr
3186 @c ====================================================================
3187 @c Indexes
3188 @c ====================================================================
3189 @node Indexes, Acknowledgments, API Quick Reference, Top
3190 @appendix Indexes
3192 @menu
3193 * Concept Index::       Well, the concept index
3194 * Function Index::      Well, the function index
3195 * Variable Index::      Well, the variable index
3196 * Data Type Index::     Well, the data type index
3197 @end menu
3200 @c --------------
3201 @c Concept Index
3202 @c --------------
3203 @node Concept Index, Function Index, Indexes, Indexes
3204 @section Concepts
3205 @printindex cp
3206 @page
3209 @c --------------
3210 @c Function Index
3211 @c --------------
3212 @node Function Index, Variable Index, Concept Index, Indexes
3213 @section Functions
3214 @printindex fn
3215 @page
3218 @c --------------
3219 @c Variable Index
3220 @c --------------
3221 @node Variable Index, Data Type Index, Function Index, Indexes
3222 @section Variables
3223 @printindex vr
3224 @page
3227 @c ---------------
3228 @c Data Type Index
3229 @c ---------------
3230 @node Data Type Index, , Variable Index, Indexes
3231 @section Data Types
3232 @printindex tp
3236 @c ====================================================================
3237 @c Acknowledgments
3238 @c ====================================================================
3239 @node Acknowledgments, , Indexes, Top
3240 @appendix Acknowledgments
3241 The following people have contributed bug reports or fixes, suggestions,
3242 compiler support or any other kind of help. You have my gratitude!
3244 @multitable @columnfractions .99
3245 Alessio Stalla@*
3246 Antony @emph{something}@*
3247 Erik Huelsmann@*
3248 Erik Winkels@*
3249 François-René Rideau@*
3250 James Wright@*
3251 Martin Simmons@*
3252 Nikodemus Siivola@*
3253 Sam Steingold@*
3254 @end multitable
3257 @bye
3259 @c  LocalWords:  Clon clon cmdline Clonification tty emph CmdLine clonified SGR
3260 @c  LocalWords:  clonfiscated clonistified clonificated clonificationated samp
3261 @c  LocalWords:  cindex subsubsection pxref Didier Nuker postfix Runtime cth
3262 @c  LocalWords:  cartouche toplevel prepended IEC
3264 @c user.texi ends here