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.
27 @c Contents management by FCM version 0.1.
30 @c ====================================================================
32 @c ====================================================================
34 @setfilename clon-user.info
35 @settitle The Clon User Manual
37 @documentencoding ISO-8859-1
42 @c ====================================================================
44 @c ====================================================================
45 @set VERSION 1.0 beta 22 "Michael Brecker"
46 @set COPYRIGHT_DATE 2010, 2011, 2012
47 @setchapternewpage odd
48 @setcontentsaftertitlepage
50 The Clon User Manual for version @value{VERSION}.
51 @end documentdescription
55 @c ====================================================================
57 @c ====================================================================
96 @option{--clon-\name\}
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}
108 @pxref{\node\, , , clon-enduser, The Clon End-User Manual}
111 @pxref{\node\, , , enduser, The Clon End-User Manual}
115 @macro xenduserref{node}
117 @xref{\node\, , , clon-enduser, The Clon End-User Manual}
120 @xref{\node\, , , enduser, The Clon End-User Manual}
124 @macro enduserref{node}
126 @ref{\node\, , , clon-enduser, The Clon End-User Manual}
129 @ref{\node\, , , enduser, The Clon End-User Manual}
143 @cindex @t{--clon-\opt\}
144 @cindex Built-In Options, @t{--clon-\opt\}
145 @cindex Options, built-in, @t{--clon-\opt\}
148 @c Common option properties
149 @macro copindex{prop}
150 @cindex Options, common properties, @t{\prop\}
151 @cindex Common Option Properties, @t{\prop\}
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\})
163 @macro voindex{name,class}
164 @cindex \name\ (@t{\class\})
165 @cindex Valued Options, \name\ (@t{\class\})
166 @cindex Options, valued, \name\ (@t{\class\})
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\}
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\}
184 @c Configuration options
186 @vindex com.dvlsoft.clon.configuration
187 @cindex Configuration Option, @t{:\name\}
196 @macro foindex{func,opt}
197 @findex \func\@r{, options, }\opt\
201 @macro fiindex{func,item}
202 @findex \func\@r{, items, }\item\
206 @macro fkindex{func,key}
207 @findex \func\@r{, keys, }\key\
211 @macro fiaindex{func,arg}
212 @findex \func\@r{, initargs, }\arg\
215 @c Generic functions sub-index
216 @macro gfsubindex{func}
217 @findex @r{Generic Functions, }\func\
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\
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\
244 @c Constructor functions
250 @c Constructor function initargs
251 @macro cfiaindex{func,arg}
252 @fiaindex{\func\, \arg\}
253 @findex @r{Constructors, }\func\@r{, initargs, }\arg\
256 @c Reader functions subindex
257 @macro rfsubindex{func}
258 @findex @r{Readers, }\func\
271 @c Environment variables
274 @vindex @r{Environment, }\var\
277 @c Built-in environment variables
278 @macro bievindex{var}
289 @tpindex @r{Classes, }\cls\
293 @macro clssindex{cls,slot}
294 @tpindex \cls\@r{, slots, }\slot\
295 @tpindex @r{Classes, }\cls\@r{, slots, }\slot\
299 @macro clsiaindex{cls,arg}
300 @tpindex \cls\@r{, initargs, }\arg\
301 @tpindex @r{Classes, }\cls\@r{, initargs, }\arg\
307 @tpindex @r{Option Classes, }\cls\
310 @c Error conditions subindex
311 @macro ecsubindex{cond}
312 @tpindex @r{Error Conditions, }\cond\
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\
328 @macro pkgindex{name}
330 @tpindex @r{Packages, }\name\
334 @macro sysindex{name}
336 @tpindex @r{Systems, }\name\
341 @c ====================================================================
342 @c Info Category and Directory
343 @c ====================================================================
344 @dircategory Common Lisp
346 * Clon User: (clon-user). The Clon User Manual.
351 @c ====================================================================
353 @c ====================================================================
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.
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).
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.
381 @c ====================================================================
383 @c ====================================================================
385 @title The Clon User Manual
386 @subtitle The @CmdLine{} Options Nuker, Version @value{VERSION}
389 @author Didier Verna <@email{didier@@lrde.epita.fr}>
391 @vskip 0pt plus 1filll
394 @hfill Cover art by Alexis Angelidis.
399 @c ====================================================================
401 @c ====================================================================
406 @c ====================================================================
408 @c ====================================================================
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.
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
436 @c ====================================================================
438 @c ====================================================================
439 @node Copying, Introduction, Top, Top
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.
458 @c ====================================================================
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 ====================================================================
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, CMUCL, CCL, ECL, CLISP, ABCL, Allegro (both
506 standard and modern) and LispWorks. @clon{} is provided as an ASDF 2
507 system, but has no mandatory dependency. CFFI may optionally be used
508 with CLISP, Allegro and LispWorks. @xref{Supported Platforms}, for more
511 In addition to the library itself, the Clon distribution offers
512 documentation in the form of 3 different manuals, some data files that
513 are needed for it to work properly, and a couple of demonstration
514 programs. Because of that, some bits of manual installation are needed.
516 After unpacking somewhere in the ASDF 2 source registry, please perform
517 the following steps, in order.
521 Edit @file{Makefile.cnf} to your specific needs.
524 Type @command{make} to compile the documentation and the demo programs
525 (end-user manual, user manual and possibly reference manual). By
526 default, the documentation is built in info, PDF and HTML formats. If
527 you want other formats (DVI and PostScript are available), type
528 @command{make all-formats}. You can also type individually @command{make
529 dvi} and/or @command{make ps} in order to get the corresponding format.
532 As documented in @file{Makefile.cnf}, the reference manual is only
533 generated if you have SBCL and the Declt library at hand (see
534 @uref{http://www.lrde.epita.fr/~didier/software/lisp/misc.php#declt}).
537 Type @command{make install} to install both the documentation and the
538 data files. If you have compiled the documentation in DVI and PostScript
539 format, those will be installed as well. The same goes for the reference
540 manual. The demo programs are not installed anywhere.
543 Type @command{make uninstall} to uninstall the library.
547 @c ====================================================================
549 @c ====================================================================
550 @node Quick Start, Using Clon, Installation, Top
552 In this chapter, we assume that you have properly installed @clon{}
553 (@pxref{Technical Notes}), and we build a very short program to get you
554 started. Let's call it @file{quickstart.lisp}.
557 * Full Source:: The complete source code
558 * Explanation:: Step-by-step code walking
565 @node Full Source, Explanation, Quick Start, Quick Start
567 For cut'n paste convenience, the complete source code is given below.
568 For a slightly longer example, have a look at the demonstration program
569 called @file{simple} in the distribution.
573 (in-package :cl-user)
576 (asdf:load-system :com.dvlsoft.clon)
577 (use-package :com.dvlsoft.clon)
579 (defsynopsis (:postfix "FILES...")
580 (text :contents "A very short program.")
581 (group (:header "Immediate exit options:")
582 (flag :short-name "h" :long-name "help"
583 :description "Print this help and exit.")
584 (flag :short-name "v" :long-name "version"
585 :description "Print version number and exit.")))
588 "Entry point for our standalone application."
590 (when (getopt :short-name "h")
593 (do-cmdline-options (option name value source)
594 (print (list option name value source)))
598 (dump "quickstart" main)
606 @node Explanation, , Full Source, Quick Start
608 Let's examine this program step-by-step now.
610 @pkgindex{com.dvlsoft.clon}@c
611 @sysindex{com.dvlsoft.clon}@c
612 First, we put ourselves in the @cl{} user package, and load @clon{} from
613 its ASDF system @samp{com.dvlsoft.clon}. Next, we use the @clon{}
614 package, also named @samp{com.dvlsoft.clon}.
618 (in-package :cl-user)
621 (asdf:load-system :com.dvlsoft.clon)
622 (use-package :com.dvlsoft.clon)
626 In fact, using the @clon{} package directly is done here for simplicity,
627 but is not recommended. In case you find the package name too long to
628 prefix every symbol with, @clon{} provides a utility function that
629 allows you to add (and use) a shorter nickname instead (the
630 demonstration programs in the distribution show how to use it):
632 @cindex Package, nicknames
633 @defun nickname-package &optional NICKNAME
634 Add NICKNAME (:CLON by default) to the :COM.DVLSOFT.CLON package.
640 @cindex Text, in synopsis
641 @cindex Options, in synopsis
642 @cindex Groups, in synopsis
644 The next thing you want to do is to create a set of options, groups or
645 texts that your application will recognize and/or display in its help
646 string. The structure of your @cmdline{} is known to @clon{} as the
647 @dfn{synopsis}. In order to create it, use the macro @code{defsynopsis}.
649 @foindex{defsynopsis,:postfix}
650 @fiindex{defsynopsis,text}
651 @fiindex{defsynopsis,options}
652 @fiindex{defsynopsis,group}
655 (defsynopsis (:postfix "FILES...")
656 (text :contents "A very short program.")
657 (group (:header "Immediate exit options:")
658 (flag :short-name "h" :long-name "help"
659 :description "Print this help and exit.")
660 (flag :short-name "v" :long-name "version"
661 :description "Print version number and exit.")))
665 Note that the synopsis has a double role: it not only serves to define
666 the options recognized by your application, but also the order in which
667 every element appears in the help string. In that particular example, we
668 define a line of text and a group with a header and two flags.
671 @cfindex{make-context}
672 Now, we are going to define a function @code{main} for our standalone
673 application. The first thing that we need to do is create a
674 @dfn{context}. A context is an object that @clon{} uses to store various
675 things, including some state related to the parsing of the @cmdline{}.
676 You create a context with the function @code{make-context}.
681 "Entry point for our standalone application."
686 @cindex Options Retrieval, explicit
687 @cindex Retrieval, of options, explicit
689 @cindex Help String, display
691 At that point, @clon{} is ready to retrieve the options you want from
692 the @cmdline{}. Let's first see if the user has called the option
693 @option{-h}, and give him the help string. Option retrieval is done with
694 the function @code{getopt}, and automatic help string output with the
695 function @code{help}. Note that what we do here is @emph{not} process
696 the @cmdline{} in sequence, but look directly for a specific option by
697 name (this retrieval method is said to be @dfn{explicit}).
699 @fkindex{getopt,:short-name}
702 (when (getopt :short-name "h")
709 The @code{exit} function is a wrapper around an
710 implementation-dependent way to exit (shall I say quit?) the @cl{}
711 environment, hence the program. It takes an optional argument that
712 stands for the exit status.
714 @cindex Options Retrieval, sequential
715 @cindex Retrieval, of options, sequential
716 @findex do-cmdline-options
717 And now, we are going to retrieve the other options and simply print
718 them. This time however, we process the @cmdline{} sequentially (so this
719 retrieval method is said to be @dfn{sequential}). This is done with the
720 @code{do-cmdline-options} macro. We also close the @code{main} function.
724 (do-cmdline-options (option name value source)
725 (print (list option name value source)))
731 Finally, time to save the Lisp image.
737 (dump "quickstart" main)
741 The first argument to @code{dump} is the name of the executable to
742 produce, and the second argument is the name of the function to call
743 automatically at startup.
745 In order to get a standalone executable from this program, all you need
746 to do now is to type @samp{CC=gcc sbcl --script quickstart.lisp}. Note
747 that the actual way of dumping executables is compiler-dependent. For
748 more information on the proper way to do it and on the compilers
749 currently supported, see @ref{Dumping Executables}.
751 Note also that it is possible to use @clon{} without actually dumping a
752 standalone executable (@pxref{Not Dumping Executables}).
756 @c ====================================================================
758 @c ====================================================================
759 @node Using Clon, Extending Clon, Quick Start, Top
762 Using @clon{} in your application is a two stages process. In phase 1,
763 you create a @dfn{synopsis}, which is a description of your
764 application's @cmdline{} and a @dfn{context}, which describes this
765 specific execution of the program. In phase 2, you retrieve the option
766 values and possibly display help strings. Phase 1 is called the
767 @dfn{initialization phase}, while phase 2 is called the @dfn{runtime
771 * Synopsis Definition:: Describing your command-line
772 * Context Creation:: Instantiating your command-line
773 * Integrity Checks:: Verifying the Clon semantics
774 * Option Retrieval:: Getting the options values
775 * Help:: Generating the help string
779 @c -------------------
780 @c Synopsis Definition
781 @c -------------------
782 @node Synopsis Definition, Context Creation, Using Clon, Using Clon
783 @section Synopsis Definition
785 @cindex Initialization Phase
786 @cindex Phase, initialization
789 Step one of the @clon{} initialization phase consists in defining a
790 @dfn{synopsis}. A synopsis is essentially a description of your
791 application's @cmdline{}: it describes what are the available options,
792 whether your application has a postfix @etc{} The synopsis, however,
793 plays a second role: it also describes the contents of your
794 application's help string. When you create a synopsis, you describe the
795 @cmdline{} and the help string at the same time.
798 * Synopsis Items:: Defsynopsis and its contents
799 * Built-In Option Types:: The exhaustive list
800 * Advanced Synopsis Creation:: The non-declarative way
803 @node Synopsis Items, Built-In Option Types, Synopsis Definition, Synopsis Definition
804 @subsection Synopsis Items
805 Look again at the synopsis definition provided in @ref{Quick Start}.
809 (defsynopsis (:postfix "FILES...")
810 (text :contents "A very short program.")
811 (group (:header "Immediate exit options:")
812 (flag :short-name "h" :long-name "help"
813 :description "Print this help and exit.")
814 (flag :short-name "v" :long-name "version"
815 :description "Print version number and exit.")))
819 You define a synopsis with the @code{defsynopsis} macro.
821 @defmac defsynopsis ([OPTIONS@dots{}]) ITEMS@dots{}
822 Define a new synopsis and return it. @var{OPTIONS} are key/value pairs.
823 @var{ITEMS} are text, group or option descriptions.
825 The following @var{OPTIONS} are currently available.
829 @foindex{defsynopsis,:postfix}@c
830 @cindex Command-Line, remainder
831 @cindex Remainder, of command-line
832 A string which will appear at the end of the synopsis line in the help
833 string. When you provide a postfix, you also implicitely tell @clon{}
834 that your application accepts non-option arguments at the end of the
835 @cmdline{} (this is called the @dfn{remainder} of the @cmdline{}). See
836 @enduserref{Option Separator} for more information on the behavior of
837 @clon{} with respect to postfixes. Also, see @ref{Command-Line
838 Remainder} on how to access the @cmdline{} remainder.
842 We now examine the syntax for each possible @var{ITEM}.
844 * Text:: Adding arbitrary text
845 * Options:: Adding options
846 * Groups:: Adding groups
849 @node Text, Options, Synopsis Items, Synopsis Items
852 @cindex Text, in synopsis
853 @fiindex{defsynopsis,text}
854 In order to add arbitrary text to your help string, use the following
858 @t{(text} [@var{OPTIONS@dots{}}]@t{)}
860 @var{OPTIONS} are key/value pairs. The following @var{OPTIONS} are
864 @cindex Text, contents
865 The actual text string. Try to make proper sentences when adding
866 arbitrary text. You can use explicit newline characters in your text if
867 you really want to go next line, but in general, you should not worry
868 about the formatting because the themes are here to do so. In
869 particular, don't finish your text with a newline. This would break
870 potential theme specifications.
875 When non-@code{nil}, the text won't appear in the help string. Hidden
876 texts can still be displayed individually though (@pxref{Help}).
879 @node Options, Groups, Text, Synopsis Items
880 @subsubsection Options
882 @cindex Options, in synopsis
883 @fiindex{defsynopsis,options}
884 In order to add an option to your help string, you must provide a list
885 beginning with the option type and followed by key/value pairs
886 describing the option's properties. For instance, to add a flag with a
887 short name and a description, you could do this:
890 (flag :short-name "h" :description "Print this help and exit.")
893 Option properties vary depending on the option type. The exact list of
894 available option types, and the corresponding properties are described
895 in @ref{Built-In Option Types}.
897 @node Groups, , Options, Synopsis Items
898 @subsubsection Groups
900 @cindex Groups, in synopsis
901 @fiindex{defsynopsis,group}
902 In order to add a group to your help string, use the following form:
905 @t{(group} ([@var{OPTIONS@dots{}}]) @var{ITEMS@dots{}}@t{)}
907 @cindex Text, in groups
908 @cindex Options, in groups
909 @cindex Groups, in groups
910 @var{OPTIONS} are key/value pairs. @var{ITEMS} simply are arbitrary
911 text, option or sub-group descriptions as we've just seen.
913 The following @var{OPTIONS} are currently available.
917 @cindex Header, in group
918 @foindex{defgroup,:header}@c
919 A string which will be displayed above the group's contents in the help
920 string. The same formatting recommendations as for arbitrary text apply
923 @cindex Hidden Groups
924 @cindex Groups, hidden
925 @foindex{defgroup,:hidden}@c
927 @cindex Built-In Groups
928 @cindex Groups, built-in
930 When non-@code{nil}, the group won't appear in the help string. Hidden
931 groups can still be displayed individually though (@pxref{Help}). For
932 instance, the @clon{} built-in group is hidden in the regular help
933 string, but the @bioption{help} option still displays it individually.
936 @node Built-In Option Types, Advanced Synopsis Creation, Synopsis Items, Synopsis Definition
937 @subsection Built-In Option Types
938 @cindex Built-In Option Types
939 @cindex Options, built-in types
940 @cindex Option Types, built-in
941 In this section, we will review all the built-in option types that
942 @clon{} provides, along with their corresponding properties. You can use
943 them directly in your synopsis description. For adding personal option
944 types to @clon{}, see @ref{New Option Types}.
947 * Common Properties:: For all options
948 * Flags:: Built-in options without arguments
949 * Common Valued Option Properties:: For all valued options
950 * Built-In Valued Options:: Built-in options with arguments
953 @node Common Properties, Flags, Built-In Option Types, Built-In Option Types
954 @subsubsection Common Properties
955 @cindex Options, common properties
956 @cindex Common Option Properties
958 All option types in @clon{}, including those you define yourself
959 (@pxref{New Option Types}), have a set of basic, common properties. Here
964 @copindex{:short-name}
965 The option's short name. A string or @code{nil}.
967 @copindex{:long-name}
968 The option's long name. A string or @code{nil}.
970 @copindex{:description}
971 The option's descriptive text. A string or @code{nil}. The same
972 formatting recommendations as for arbitrary text apply (@pxref{Text}).
975 The option's associated environment variable. A string or @code{nil}.
978 @cindex Hidden Options
979 @cindex Options, hidden
981 When non-@code{nil}, the option won't appear in the help string. Hidden
982 options can still be displayed individually though (@pxref{Help}).
985 Note that an option is required to have at least one name (either short
986 or long). Non-@code{nil} but empty names are also prohibited, and of
987 course, a short name cannot begin with a dash (otherwise, it would be
988 mistaken for a long name, but did I really need to mention this?).
990 @node Flags, Common Valued Option Properties, Common Properties, Built-In Option Types
993 In @clon{}, options that don't take any argument are of type
994 @code{flag}. These options don't provide additional properties on top of
995 the common set described in @ref{Common Properties}. All properties
996 default to @code{nil}.
998 @node Common Valued Option Properties, Built-In Valued Options, Flags, Built-In Option Types
999 @subsubsection Common Valued Option Properties
1000 @cindex Valued Options
1001 @cindex Options, valued
1002 @clsindex{valued-option}
1003 All non-flag options in @clon{} are said to be @dfn{valued}. All valued
1004 options, including those you define yourself (@pxref{New Option Types}),
1005 share a set of additional properties. Here is a list of them.
1007 @cindex Valued Options, common properties
1008 @cindex Common Valued Option Properties
1009 @cindex Options, valued, common properties
1011 @item :argument-name
1012 @cvopindex{:argument-name}
1013 The name of the option's argument, as it appears in the help string. It
1014 defaults to @code{"ARG"}, so that for instance, a @samp{name} option
1015 would appear like this: @samp{--name=ARG}.
1016 @item :argument-type
1017 @cvopindex{:argument-type}
1018 The status of the argument. Possible values are @code{:required} (the
1019 default) and @code{:mandatory} which are synonyms, or @code{:optional}.
1020 @item :fallback-value
1021 @cvopindex{:fallback-value}
1022 @cindex Values, source, fallback
1023 @item :default-value
1024 @cvopindex{:default-value}
1025 @cindex Values, source, default
1026 The option's fallback and default values. Remember that a fallback value
1027 only makes sense when the argument is optional. Besides, also when the
1028 argument is optional, you need to provide at least a fallback or a
1029 default value (or both of course; see @enduserref{Value Sources}).
1032 @node Built-In Valued Options, , Common Valued Option Properties, Built-In Option Types
1033 @subsubsection Built-In Valued Options
1034 @cindex Option Types, valued
1035 @cindex Built-In Option Types, valued
1036 @cindex Options, built-in types, valued
1037 @cindex Option Types, built-in, valued
1038 @clon{} currently defines 6 built-in valued option types. These option
1039 types may change the default value for some common properties, and / or
1040 provide additional properties of their own. All of this is described
1045 @voindex{Strings,stropt}@c
1046 @cvopindex{:argument-name}@c
1047 This option type is for options taking strings as their argument. String
1048 options don't provide any additional properties, but their default
1049 argument name is changed from @code{"ARG"} to @code{"STR"}.
1051 @voindex{Lisp Objects,lispobj}@c
1052 @cvopindex{:argument-name}@c
1053 @vopindex{Lisp Objects,lispobj,:typespec}@c
1054 @bioindex{line-width}@c
1055 This option type is for options taking any kind of Lisp object as their
1056 argument. @code{lispobj} options change their default argument name from
1057 @code{"ARG"} to @code{"OBJ"}. Also, they provide an additional property
1058 called @code{:typespec} which must be a @cl{} type specifier that the
1059 argument must satisfy. It defaults to @code{t}. Look at the
1060 @bioption{line-width} built-in option for an example.
1062 @voindex{Enumerations,enum}@c
1063 @cvopindex{:argument-name}@c
1064 @vopindex{Enumerations,enum,:enum}@c
1065 @bioindex{version}@c
1066 This option type is for options taking values from an enumerated set of
1067 keywords. @code{enum} options change their default argument name from
1068 @code{"ARG"} to @code{"TYPE"}. Also, they provide an additional property
1069 called @code{:enum} to store the list of @cl{} keywords enumerating the
1070 possible values. The end-user does not use a colon when providing an
1071 argument to an @code{enum} option. Only the keyword's name. The end-user
1072 also has the ability to abbreviate the possible values. An empty
1073 argument is considered as an abbreviation for the first element in the
1074 set. Look at the @bioption{version} built-in option for an example.
1076 @bioindex{search-path}@c
1078 @voindex{Paths,path}@c
1079 @cvopindex{:argument-name}@c
1080 @vopindex{Paths,path,:type}@c
1081 This option type is for options taking a colon-separated list of
1082 pathnames as argument. @code{path} options change their default argument
1083 name from @code{"ARG"} to @code{"PATH"}. Also, they provide an
1084 additional property called @code{:type} which specifies the kind of path
1085 which is expected. Possible values are: @code{:file}, @code{:directory},
1086 @code{:file-list}, @code{:directory-list} or @code{nil} (meaning that
1087 anything is allowed). Null paths are allowed, and may be provided by an
1088 empty argument. Look at the @bioption{search-path} and
1089 @bioption{theme} built-in options for examples.
1091 @voindex{Switches,switch}@c
1092 @cvopindex{:argument-name}@c
1093 @cvopindex{:argument-type}@c
1094 @vopindex{Switches,switch,:argument-style}@c
1095 This option type is for Boolean options. @code{switch} options change
1096 their default argument type from required to optional and provide a
1097 fallback value of @code{t} automatically for optional arguments.
1098 @code{switch} options provide a new property called
1099 @code{:argument-style}. Possible values are @code{:yes/no} (the
1100 default), @code{:on/off}, @code{:true/false}, @code{:yup/nope},
1101 @code{:yeah/nah}. This property affects the way the argument name and
1102 true or false values are advertized in help strings. However, all
1103 possible arguments forms (@pxenduserref{Switches}) are always available
1106 @voindex{Extended Switches,xswitch}@c
1107 @cvopindex{:argument-name}@c
1108 @cvopindex{:argument-type}@c
1109 @vopindex{Extended Switches,xswitch,:argument-style}@c
1110 @vopindex{Extended Switches,xswitch,:enum}@c
1111 @bioindex{highlight}@c
1112 This option type stands for @dfn{extended} switch. Extended switches
1113 result from the mating of a male switch and a female enumeration, or the
1114 other way around (elementary decency prevents me from describing this
1115 mating process in detail): their possible values are either Boolean or
1116 from an @code{:enum} property as in the case of @code{enum} options. As
1117 simple switches, @code{xswitch} options change their default argument
1118 type from required to optional and provide a fallback value of @code{t}
1119 automatically for optional arguments. They also provide the
1120 @code{:argument-style} property. Contrary to switches, however, this
1121 property does not affect the argument name. It only affects the way true
1122 or false values are displayed in help strings. Look at the
1123 @bioption{highlight} built-in option for an example.
1126 @node Advanced Synopsis Creation, , Built-In Option Types, Synopsis Definition
1127 @subsection Advanced Synopsis Creation
1129 The fact that @code{defsynopsis} lets you define things in a
1130 @emph{declarative} way has not escaped you. Declarative is nice but
1131 sometimes it gets in the way, so it is time to see how things work under
1132 the hood. Every item in a synopsis is in fact implemented as an object
1133 (an instance of some class), so it turns out that @code{defsynopsis}
1134 simply is a convenience wrapper around the corresponding constructor
1135 functions for all such objects. Instead of using @code{defsynopsis}, you
1136 can then use those constructor functions explicitely.
1139 * Constructors:: The expansion of defsynopsis
1140 * Advantages:: Yes, but why?
1141 * Group Definition:: The declarative way
1144 @node Constructors, Advantages, Advanced Synopsis Creation, Advanced Synopsis Creation
1145 @subsubsection Constructors
1146 Let's have a look at the expansion of @code{defsynopsis} from the quick
1147 start example (@pxref{Quick Start}).
1149 The original code is like this:
1153 (defsynopsis (:postfix "FILES...")
1154 (text :contents "A very short program.")
1155 (group (:header "Immediate exit options:")
1156 (flag :short-name "h" :long-name "help"
1157 :description "Print this help and exit.")
1158 (flag :short-name "v" :long-name "version"
1159 :description "Print version number and exit.")))
1163 And once the macro is expanded, it will look like this:
1165 @cfindex make-synopsis
1169 @findex defsynopsis@r{, expansion}
1172 (make-synopsis :postfix "FILES..."
1173 :item (make-text :contents "A very short program.")
1174 :item (make-group :header "Immediate exit options:"
1175 :item (make-flag :short-name "h"
1177 :description "Print this help and exit.")
1178 :item (make-flag :short-name "v"
1179 :long-name "version"
1180 :description "Print version number and exit.")))
1184 As you can see, every synopsis element has a corresponding
1185 @code{make-@var{SOMETHING}} constructor, and the keywords used here and
1186 there in @code{defsyopsis} are in fact initargs to those constructors.
1187 We now examine those constructors in greater detail.
1189 @cindex Options, creation
1190 @defun make-text [@code{:hidden} BOOL] @code{:contents} STRING
1191 @cfsubindex{make-text}
1192 @cfiaindex{make-text,:contents}
1193 @cfiaindex{make-text,:hidden}
1194 Create an arbitrary text object, possibly hidden, whose contents is
1198 @c #### FIXME: I would like an environment without indexing here.
1199 @defun make-@var{OPTION} :INITARG INITVAL@dots{}
1200 @cfsubindex{make-@var{OPTION}}
1202 @cfindex make-stropt
1203 @cfindex make-lispobj
1206 @cfindex make-switch
1207 @cfindex make-xswitch
1208 Create a new @var{OPTION} object, @var{OPTION} being any built-in option
1209 type (@code{flag}, @code{stropt} @etc{}, see @ref{Built-In Valued
1210 Options}) or user-defined one (@pxref{New Option Types}). For a list of
1211 available initialization arguments (depending on the option type), see
1212 @ref{Built-In Option Types}.
1215 @defun make-group [@code{:header} STRING @code{:hidden} BOOL] @
1216 @code{:item} ITEM1 @code{:item} ITEM2@dots{}
1217 @cfsubindex{make-group}
1218 @cfiaindex{make-group,:header}
1219 @cfiaindex{make-group,:hidden}
1220 @cfiaindex{make-group,:item}
1222 Create a group object, possibly hidden, whose header is @var{STRING}.
1223 Every @var{ITEM} is an arbitrary text object, option object or group
1224 object. The order is important as it determines the display of the help
1228 @defun make-synopsis [@code{:postfix} STRING] @
1229 @code{:item} ITEM1 @code{:item} ITEM2@dots{}
1230 @cfsubindex{make-synopsis}
1231 @cfiaindex{make-synopsis,:postfix}
1232 @cfiaindex{make-synopsis,:item}
1234 Create a synopsis object whose postfix is @var{STRING}. Every @var{ITEM} is
1235 an arbitrary text object, option object or group object. The order is
1236 important as it determines the display of the help string.
1239 In fact, the @code{defsynopsis} macro allows you to freely mix
1240 declarative forms, constructor calls or whatever Lisp code you may want
1241 to use. The way this works is as follows: if a synopsis @var{ITEM}
1242 (@pxref{Synopsis Items}) is a list whose @code{car} is @code{text},
1243 @code{group}, or any option type (inluding those you define yourselves;
1244 see @ref{New Option Types}), then the @var{ITEM} is expanded as
1245 explained earlier. Otherwise, it is just left @emph{as-is}.
1247 To sum up, here's a example of things you can do in @code{defsynopsis}.
1251 (com.dvlsoft.clon:defsynopsis ()
1254 (setq *another-option* (com.dvlsoft.clon:make-switch #| ... |#)))
1259 @node Advantages, Group Definition, Constructors, Advanced Synopsis Creation
1260 @subsubsection Advantages
1262 So, why would you want to use constructors directly or mix declarative
1263 and imperative forms in @code{defsynopsis}? There are several reasons
1267 Some people prefer to declare (or should I say, create) their arbitrary
1268 texts, options and groups locally, in files, modules or ASDF components
1269 where they belong. In such a case, you need to keep references to the
1270 corresponding objects in order to compute the synopsis in the end.
1272 Since using constructors explicitely allows you to keep references to
1273 the created objects, these objects can be @emph{reused}. For instance,
1274 you can use the same text at different places, you can also use a single
1275 option several times, or even a single group several times so that its
1276 items appear in different places @etc{} Note that @clon{} knows its way
1277 around multiple occurrences of the same object: even if you use the same
1278 option object several times in a synopsis, @clon{} only maintains a
1279 single option definition.
1282 @node Group Definition, , Advantages, Advanced Synopsis Creation
1283 @subsubsection Group Definition
1284 There is one last point we need to address in order to complete this
1285 section. There might be times when you need to manipulate an explicit
1286 group object, but the object itself can still be created in a
1287 declarative (or mixed) way because you don't need to keep references on
1288 its items. For this, @clon{} provides a macro called @code{defgroup}.
1290 @defmac defgroup (OPTIONS@dots{}) ITEMS@dots{}
1291 @cindex Groups, in synopsis
1292 @fiindex{defsynopsis,group}
1293 @foindex{defgroup,:header}
1294 @foindex{defgroup,:hidden}
1295 Define a new group and return it. This macro behaves exactly like the
1296 @code{group} form in a call to @code{defsynopsis} (@pxref{Groups}). In
1297 fact, an intermediate step in the expansion of the @code{defsynopsis}
1298 macro is to transform @code{group} forms into @code{defgroup} macro
1299 calls. As for @code{defsynopsis}, @code{defgroup} allows you to mix
1300 declarative forms, constructor calls or any kind of Lisp code.
1308 @node Context Creation, Integrity Checks, Synopsis Definition, Using Clon
1309 @section Context Creation
1311 @cindex Initialization Phase
1312 @cindex Phase, initialization
1314 Step two of the @clon{} initialization phase consists in creating a
1315 @dfn{context}. A context is an object representing a particular instance
1316 of your program, for example (and most notably) with an actual
1317 @cmdline{} as the user typed it.
1320 * Making A Context:: The Constructor function
1321 * Contextual Information:: Interesting context slots
1324 @node Making A Context, Contextual Information, Context Creation, Context Creation
1325 @subsection Making A Context
1327 @cfindex{make-context}
1328 You create a context with the @code{make-context} function.
1331 @cfsubindex{make-context}
1332 Create a new context. That's it.
1335 @node Contextual Information, , Making A Context, Context Creation
1336 @subsection Contextual Information
1338 Once a context object is created, you have access to some interesting
1339 contextual information.
1342 * Program Name:: As it appear on the command-line
1343 * Command-Line Remainder:: The non-options part
1344 * Command-Line Polling:: Whether something is left
1347 @node Program Name, Command-Line Remainder, Contextual Information, Contextual Information
1348 @subsubsection Program Name
1349 The application's program name, as it appears on the @cmdline{}, may be
1350 accessed from @clon{}. You may find it easier to do this way, as @clon{}
1351 wraps around implementation-dependent access methods to @code{argv[0]}.
1354 In order to retrieve @code{argv[0]}, use the @code{progname} function
1355 like this: @code{(progname)}.
1357 @node Command-Line Remainder, Command-Line Polling, Program Name, Contextual Information
1358 @subsubsection Command-Line Remainder
1359 @cindex Remainder, of command-line
1360 @cindex Command-Line, remainder
1361 In the case your @cmdline{} has a remainder (that is, a non-options
1362 part; see @enduserref{Option Separator} and @ref{Synopsis Items}), you
1363 may need to access it in order to process it independently from @clon{}.
1364 Since @clon{} is responsible for parsing the @cmdline{}, it is also in
1365 charge of figuring out where the remainder of the @cmdline{} begins.
1368 The @cmdline{} remainder is known to @clon{} as soon as a context is
1369 created. You can retrieve it by using the @code{remainder} function like
1370 this: @code{(remainder)}. The remainder is provided as a list of strings.
1372 @node Command-Line Polling, , Command-Line Remainder, Contextual Information
1373 @subsubsection Command-Line Polling
1374 @cindex Polling, of command-line
1375 @cindex Command-Line, polling
1377 @clon{} provides two utility functions to inquire on the current status
1380 @findex cmdline-options-p
1382 The function @code{cmdline-options-p} returns true if there are still
1383 unprocessed options on the @cmdline{}. The function @code{cmdline-p}
1384 returns true if there's @emph{anything} left on the @cmdline{}, that is,
1385 either unprocessed options, or a remainder. A potential use of
1386 @code{cmdline-p} at a very early stage of your application could be to
1387 automatically display a help string if the @cmdline{} is effectively
1394 @node Integrity Checks, Option Retrieval, Context Creation, Using Clon
1395 @section Integrity Checks
1397 @cfindex{make-context}
1398 At this point, you know about the two necessary steps to initialize
1399 @clon{}: defining a synopsis and creating a context. If you paid
1400 attention to the quick start application (@pxref{Quick Start}), you may
1401 have noticed that @code{defsynopsis} was called as a top-level form
1402 whereas @code{make-context} was called from the function @code{main}. So
1405 First, I hope that you see why a context cannot be created as a toplevel
1406 form. If you do that, you will end-up creating a context relevant to the
1407 Lisp environment from which the application is created, not run.
1409 The synopsis, on the other hand, could be defined either as a toplevel
1410 form, as done in the quick start and the demo programs, or in the
1411 function @code{main}, just before making a context. There is a very good
1412 reason to prefer a toplevel form however: that reason is called
1413 ``integrity checks''.
1415 When you define a synopsis (or any synopsis item, for that matter),
1416 @clon{} performs a number of checks to make sure that you're making a
1417 sensible use of the library. In fact, the number of semantic mistakes
1418 that you can make is quite puzzling. You could for instance define
1419 several options with identical names, forget to provide a fallback or
1420 default value when it is required, provide invalid fallback or default
1421 values, and the list goes on and on. These are just a few examples but
1422 there are many more, and @clon{} checks all of those (I think).
1424 Since those mistakes relate to the definition of the application itself,
1425 they do not depend on a particular execution of it. Consequently, the
1426 sooner @clon{} catches them, the better. If you define your
1427 application's synopsis as a toplevel form, @clon{} will be able to
1428 perform its integrity checks when the application is created, not only
1429 when it is used. In other words, you won't be able to get a working
1430 application until your use of @clon{} is semantically correct.
1432 This is why it is strongly recommended to create synopsis from toplevel
1433 forms, and this also explains why @clon{} chooses @emph{not} to provide
1434 an @code{initialize} function that would wrap around @code{defsynopsis}
1435 and @code{make-context} together.
1442 @node Option Retrieval, Help, Integrity Checks, Using Clon
1443 @section Option Retrieval
1444 @cindex Runtime Phase
1445 @cindex Phase, runtime
1446 @cindex Retrieval, of options
1447 @cindex Options Retrieval
1449 During the runtime phase of @clon{}, your main activity will be to
1450 retrieve options and their values. @clon{} provides two techniques for
1451 retrieving options: you can request the value for a specific option
1452 directly, or you can process the @cmdline{} sequentially, which is the
1453 more traditional approach.
1455 @cindex Command-Line
1457 Both of these techniques can be freely combined together at any time,
1458 because @clon{} keeps track of the current status of the @cmdline{}. In
1459 fact, @clon{} never works on the original @cmdline{}, but uses a mutable
1460 @emph{copy} of it after parsing. If you want to access the real
1461 @cmdline{} of your application (except for the compiler-specific
1462 options, see @ref{Not Dumping Executables}), you may use the
1463 @code{cmdline} function, which is a wrapper around an
1464 implementation-dependent way to access it.
1467 Finally, remember that the @cmdline{} is scanned from left to right
1468 during option retrieval (@pxenduserref{Option Retrieval}).
1471 * Explicit Retrieval:: Accessing options by name
1472 * Sequential Retrieval:: Accessing options in order
1475 @node Explicit Retrieval, Sequential Retrieval, Option Retrieval, Option Retrieval
1476 @subsection Explicit Retrieval
1477 @cindex Options Retrieval, explicit
1478 @cindex Retrieval, of options, explicit
1479 Since @clon{} lets you retrieve options on demand (at any time), it
1480 makes sense to be able to request the value of a specific option
1481 explicitely. For instance, you might want to try the @samp{--help}
1482 option first, without looking at the rest of the @cmdline{} because the
1483 application will in fact quit immediately after having displayed the
1486 @defun getopt :KEY VALUE@dots{}
1487 Retrieve the value of a specific option. The following @var{:KEY}s are
1488 currently available.
1493 @fkindex{getopt,:short-name}
1494 @fkindex{getopt,:long-name}
1495 Use one of these 2 keys to specify the name of the option you wish to
1498 @fkindex{getopt,:option}
1499 Alternatively, you can use a reference to an option object
1500 (@pxref{Constructors}).
1503 This function return two values: the option's value and the value's
1504 source (@pxenduserref{Value Sources}).
1507 The value's source may have the following forms:
1509 @item (:cmdline @var{NAME})
1510 @cindex Values, source, @cmdline{}
1511 This is for options found on the @cmdline{}. @var{NAME} is the name used
1512 on the @cmdline{}. It can be the option's long or short name, or a
1513 completed long name if the option's name was abbreviated. A completed
1514 name displays the omitted parts in parentheses (@code{"he(lp)"} for
1516 @item (:fallback @var{NAME})
1517 @cvopindex{:fallback-value}
1518 @cindex Values, source, fallback
1519 The same but when the fallback value is used, that is, when an option is
1520 not provided with its (optional) argument.
1521 @item (:default @var{NAME})
1522 @cvopindex{:default-value}
1523 @cindex Values, source, default
1524 The same, but when the default value is used (because there is no
1526 @item (:environment @var{VAR})
1528 @cindex Values, source, environment
1529 This is for options not found on the @cmdline{} but for which there is
1530 an associated environment variable set in the application's environment.
1531 @var{VAR} is the name of the corresponding environment variable.
1533 @cvopindex{:default-value}
1534 @cindex Values, source, default
1535 This is for options not found anywhere, but for which a default value
1541 Note that because flags don't take any argument, @code{getopt} returns a
1542 virtual value of @code{t} when they are found or a corresponding
1543 environment variable exists in the environment. For the same reason, a
1544 flag's value source may ony be @code{(:cmdline @var{NAME})} or
1545 @code{(:environment @var{VAR})}.
1548 When an option is not found anywhere and there is no default value,
1549 @code{getopt} just returns nil (no second value). Also, note that when
1550 your option accepts @code{nil} as a value, you @emph{need} to handle the
1551 second retrun value to make the difference between an option not found,
1552 and an actual value of @code{nil}.
1555 @node Sequential Retrieval, , Explicit Retrieval, Option Retrieval
1556 @subsection Sequential Retrieval
1557 @cindex Options Retrieval, sequential
1558 @cindex Retrieval, of options, sequential
1559 The more traditional approach to option retrieval is to scan the
1560 @cmdline{} for options in their order of appearance. @clon{} supports
1561 this by providing you with one function and two macros, as explained
1564 @defun getopt-cmdline
1565 Get the @dfn{next} @cmdline{} option, that is, the first option on the
1566 @cmdline{} that has not been previously retrieved, either explicitely or
1569 When there are no more options on the @cmdline{}, this function returns
1570 @code{nil}. Otherwise, four values are returned: the corresponding
1571 option object from the synopsis definition (@pxref{Constructors}), the
1572 name used on the @cmdline{}, the option's value and the value source
1573 (@code{:cmdline}, @code{:fallback} or @code{:default}). As in the case
1574 of explicit retrieval (@pxref{Explicit Retrieval}), the option's name
1575 may be completed in case of abbreviation.
1577 @rfindex{short-name}
1579 @copindex{:short-name}
1580 @copindex{:long-name}
1581 Unless you keep references to all your option objects (and thus can
1582 compare them directly to the one returned by this function), you can
1583 still identify the retrieved option by using the @code{short-name} and
1584 @code{long-name} readers on it: simply use @code{(long-name
1585 @var{OPTION})} or @code{(short-name @var{OPTION})} and you will get the
1586 corresponding strings.
1589 @defmac multiple-value-getopt-cmdline (OPTION NAME VALUE SOURCE) BODY
1590 Evaluate @var{BODY} with @var{OPTION}, @var{NAME}, @var{VALUE} and
1591 @var{SOURCE} bound to the values returned by the @code{getopt-cmdline}
1592 function above. Note that @var{BODY} is not evaluated if there was no
1593 remaining option on the @cmdline{}, so you don't need to conditionalize
1594 on @var{OPTION} being @code{null} yourself.
1597 @defmac do-cmdline-options (OPTION NAME VALUE SOURCE) BODY
1598 As above, but loop over all @cmdline{} options.
1605 @node Help, , Option Retrieval, Using Clon
1608 One of the first motivations in the design of @clon{} was to automate
1609 the generation of the help string, which is a very boring maintenance
1610 task to do by hand. The application's synopsis contains all the
1611 necessary information to do so. In order to print your application's
1612 help string, use the @code{help} function.
1614 @defun help [@code{:item} ITEM]
1615 @bioindex{search-path}
1616 @bievindex{SEARCH_PATH}
1617 @bioindex{highlight}
1618 @bievindex{HIGHLIGHT}
1621 @bioindex{line-width}
1622 @bievindex{LINE_WIDTH}
1623 Print the application's help string. Printing honors the search path,
1624 theme, line width and highlight settings provided by the corresponding
1625 built-in options (@pxenduserref{Theme Mechanism}).
1628 @fkindex{help,:item}
1629 By default, @code{help} prints the whole application help string,
1630 excluding hidden items. However, if you have kept a reference to any
1631 synopsis item (option, text, group), you can pass it as the value of the
1632 @code{:item} key, and @clon{} will only print the help string for that
1633 particular item. In this case however, the hidden state of the item is
1634 discarded (but @emph{not} the ones of sub-items).
1637 @cindex Built-In Groups
1638 @cindex Groups, built-in
1639 @cindex Hidden Groups
1640 @cindex Groups, hidden
1641 For instance, the @clon{} built-in group is normally hidden, so it
1642 doesn't show up in the global help string, but the @bioption{help}
1643 option uses the @code{help} function on it explicitely, so it discards
1646 Here is a potentially useful application of hidden groups in conjunction
1647 with the @code{:item} key. Look at ImageMagick's @file{convert}
1648 program's help string for instance: it is 276 lines long. Gosh. The help
1649 string is decomposed into several categories: image settings, image
1650 operators, misc options @etc{}. If I were to implement this program, I
1651 would rather have the @option{--help} option display an overview of the
1652 program, advertise @option{--version} and a couple of others, and I
1653 would then implement @option{--help} as an enumeration for listing every
1654 option category individually (they would normally be stored in hidden
1655 groups). The user could then use @option{--help=settings},
1656 @option{--help=operators} and so on to display only the category she's
1659 Finally, here is potentially useful application of hidden options that
1660 are never ever displayed in any help string whatsoever, and I mean,
1661 like, ever. This is the perfect tool for backdoor'ing a program. For
1662 instance, if you ever need to implement a
1663 @option{--discard-all-security-measures-and-blow-the-nuke} option, then
1664 you'd better have it hidden@dots{}
1668 @c ====================================================================
1670 @c ====================================================================
1671 @node Extending Clon, Advanced Usage, Using Clon, Top
1672 @chapter Extending Clon
1674 As you know, @clon{} already provides seven built-in option types: flags
1675 and six other types for valued options (@pxref{Built-In Valued
1676 Options}). After using @clon{} for a while, you may find that however
1677 brilliant and perfectly designed it is, none of the provided built-in
1678 types fullfill your requirements exactly. There are two ways around
1679 this: the right way and the wrong way (hint).
1681 @voindex{Strings,stropt}
1682 The wrong, although perhaps quicker way would be to use the
1683 @code{stropt} option type to simply retrieve unprocessed string values,
1684 and then do whatever tweaking required on them. In doing so, you risk
1685 reinventing some of @clon{}'s wheels.
1687 The right way is to define a new option type. Properly defined option
1688 types are a good thing because they allow for reusability and also
1689 extensibility, since new option types can always be defined on top of
1691 @voindex{Enumerations,enum}
1692 In this chapter we explain how to extend @clon{} by providing new option
1693 types. We illustrate the process with the example of the built-in
1696 @cindex Valued Options
1697 @cindex Options, valued
1699 Oh, and I almost forgot. I hope it is obvious to everyone that new
1700 option types are always @emph{valued}. There's no point in extending
1701 @clon{} with options that don't take any arguments, since we already
1705 * New Option Types:: In four steps
1706 * Extension Tips:: Some advice
1713 @node New Option Types, Extension Tips, Extending Clon, Extending Clon
1714 @section New Option Types
1715 @cindex Option Types, in files
1716 @cindex Files, one per option type
1717 @pkgindex{com.dvlsoft.clon}
1718 From a software engineering point of view, it is better to implement new
1719 option types in a file of their own, preferably named after the option
1720 type itself, and to put this file in the @clon{} package, like this:
1724 (in-package :com.dvlsoft.clon)
1728 Creating your own option type involves 5 steps: providing a class for
1729 them, implementing three protocols related to argument/value tweaking,
1730 and providing a constructor function. We now review those 5 steps in
1734 * New Option Classes:: Step 1
1735 * Value Check Protocol:: Step 2
1736 * Argument Conversion Protocol:: Step 3
1737 * Error Management:: In-between steps coffee time!
1738 * Value Stringification Protocol:: Step 4
1739 * Constructor Functions:: Step 5
1742 @node New Option Classes, Value Check Protocol, New Option Types, New Option Types
1743 @subsection New Option Classes
1745 @clsindex{valued-option}
1746 @clon{} maintains a class hierarchy for all option types. The mother of
1747 all option types is the @code{option} abstract class. It handles the
1748 options'short and long names, description and associated environment
1749 variable (@pxref{Common Properties}). Valued options inherit from an
1750 abstract subclass of @code{option} called @code{valued-option}. This
1751 class handles the option's argument name and status (optional or
1752 mandatory), fallback and default values (@pxref{Common Valued Option
1755 @cindex User-Defined Option Classes
1756 @cindex Option Classes, user-defined
1757 In order to create a new option type, use the @code{defoption} macro.
1759 @defmac defoption CLASS SUPERCLASSES SLOTS &rest OPTIONS
1760 Create a new option CLASS and register it with @clon{}.
1761 Syntactically, thismacro behaves like @code{defclass}. Option types
1762 created like this implicitely inherit from @code{valued-option} and in
1763 turn @code{option}, so you don't need to put them explicitely in the
1764 @var{SUPERCLASSES} list.
1767 Let's look at the enumeration example now.
1771 (defoption enum (enum-base)
1772 ((argument-name ;; inherited from the VALUED-OPTION class
1774 (:documentation "The ENUM class.
1775 This class implements options whose values belong to a set of keywords."))
1779 @voindex{Enumerations,enum}
1780 @vopindex{Enumerations,enum,:enum}
1781 @voindex{Extended Switches,xswitch}
1782 @vopindex{Extended Switches,xswitch,:enum}
1783 @clsindex{enum-base}
1784 As you can see, this class inherits from @code{enum-base}, which is the
1785 class handling the @code{:enum} property. The reason for this split is
1786 that there are currently two option types providing enumeration-like
1787 facility: @code{enum} and @code{xswitch}, so @code{xswitch} also
1788 inherits from @code{enum-base}.
1790 @clsindex{valued-option}
1791 @cvopindex{:argument-name}
1792 There are no new slots in this class, but the @code{argument-name} slot
1793 provided by the @code{valued-option} class has its initform changed from
1794 @code{"ARG"} to @code{"TYPE"}.
1796 @node Value Check Protocol, Argument Conversion Protocol, New Option Classes, New Option Types
1797 @subsection Value Check Protocol
1798 @cindex Value Check Protocol
1799 @cindex Protocols, value check
1800 Now that we have our new option class, we need to implement the
1801 so-called @dfn{value check} protocol. This protocol is used to make sure
1802 that values provided for options of your new type actually comply with
1803 the type in question. Values going through this protocol are fallback
1804 values, default values, and values provided from a debugger restart
1805 (@pxenduserref{Error Management}). In the case of fallback and default
1806 values (which, by the way, are provided by @emph{you}, the @clon{}
1807 user), the check is performed only once, when the option object is
1808 created. Values provided from a debugger restart come from the
1809 application end-user, and hence are checked every time.
1811 The value check protocol is implemented through a @code{check} generic
1812 function for which you must provide a method.
1814 @deffn {Generic Function} check OPTION VALUE
1816 @ecindex invalid-value
1817 Check that @var{VALUE} is valid for @var{OPTION}. If @var{VALUE} is
1818 valid, return it. Otherwise, raise an @code{invalid-value} error.
1821 As you can see, you need to provide a method with the first argument
1822 specialized to your new option type. This method must return @var{VALUE}
1823 if it is okay, and raise an @code{invalid-value} error otherwise.
1825 @ecindex invalid-value
1826 @clon{} maintains a hierarchy of error conditions. The
1827 @code{invalid-value} error condition is defined like this:
1831 (define-condition invalid-value (option-error)
1832 ((value :documentation "The invalid value."
1835 (comment :documentation "An additional comment about the error."
1839 (:report (lambda (error stream)
1840 (format stream "Option ~A: invalid value ~S.~@[~%~A~]"
1841 (option error) (value error) (comment error))))
1842 (:documentation "An invalid value error."))
1846 @ecindex invalid-value
1847 @ecsindex{invalid-value,value}
1848 @ecsindex{invalid-value,comment}
1849 When the error is raised, you must fill in the @code{value} and
1850 @code{comment} slots appropriately.
1851 @ecindex option-error
1852 @ecsindex{option-error,option}
1853 The super-condition @code{option-error} provides an additional
1854 @code{option} slot that you must also fill in when the error is raised.
1856 @gfmindex{check,@r{Enumerations (}enum@r{)}}
1857 @voindex{Enumerations,enum}
1858 @vopindex{Enumerations,enum,:enum}
1859 @findex list-to-string
1860 Let's look at the enumeration example now.
1864 (defmethod check ((enum enum) value)
1865 "Check that VALUE is a valid ENUM."
1866 (unless (member value (enum enum))
1867 (error 'invalid-value
1870 :comment (format nil "Valid values are: ~A."
1871 (list-to-string (enum enum)
1872 :key #'prin1-to-string))))
1877 This code should be self-explanatory. We check that the value we got
1878 belongs to the enumeration. @code{list-to-string} is a utility function
1879 that will separate every element with comas in the resulting string.
1881 @node Argument Conversion Protocol, Error Management, Value Check Protocol, New Option Types
1882 @subsection Argument Conversion Protocol
1883 @cindex Argument Conversion Protocol
1884 @cindex Protocols, argument conversion
1885 The next protocol we need to implement is the so-called @dfn{argument
1886 conversion} protocol. This protocol is used to convert option arguments
1887 (that is, strings) to an actual value of the proper type. Arguments
1888 going through this protocol come from the @cmdline{}, the value of an
1889 environment variable or a debugger restart (@pxenduserref{Error
1890 Management}). Also, note that @clon{} assumes that you implement this
1891 protocol correctly, so no value check is performed on values coming from
1892 the conversion of an argument.
1894 The conversion protocol is implemented through a @code{convert} generic
1895 function for which you must provide a method.
1897 @deffn {Generic Function} convert OPTION ARGUMENT
1898 @gfsubindex{convert}
1899 @ecindex invalid-argument
1900 Convert @var{ARGUMENT} to @var{OPTION's} value. If @var{ARGUMENT} is
1901 invalid, raise an @code{invalid-argument} error.
1904 As you can see, you need to provide a method with the first argument
1905 specialized to your new option type. This method must return the
1906 conversion of @var{ARGUMENT} to the appropriate type if it is valid, and
1907 raise an @code{invalid-argument} error otherwise.
1909 @ecindex invalid-argument
1910 The @code{invalid-argument} error condition is defined like this:
1914 (define-condition invalid-argument (option-error)
1915 ((argument :documentation "The invalid argument."
1919 (comment :documentation "An additional comment about the error."
1923 (:report (lambda (error stream)
1924 (format stream "Option ~A: invalid argument ~S.~@[~%~A~]"
1925 (option error) (argument error) (comment error))))
1926 (:documentation "An invalid argument error."))
1930 @ecindex invalid-argument
1931 @ecsindex{invalid-argument,argument}
1932 @ecsindex{invalid-argument,comment}
1933 When the error is raised, you must fill in the @code{argument} and
1934 @code{comment} slots appropriately.
1935 @ecindex option-error
1936 @ecsindex{option-error,option}
1937 As before, the super-condition @code{option-error} provides an
1938 additional @code{option} slot that you must also fill in when the error
1941 @gfmindex{convert,@r{Enumerations (}enum@r{)}}
1942 @voindex{Enumerations,enum}
1943 @vopindex{Enumerations,enum,:enum}
1944 @findex closest-match
1945 Let's look at the enumeration example now.
1949 (defmethod convert ((enum enum) argument)
1950 "Convert ARGUMENT to an ENUM value."
1951 (or (closest-match argument (enum enum) :ignore-case t :key #'symbol-name)
1952 (error 'invalid-argument
1955 :comment (format nil "Valid arguments are: ~A."
1956 (list-to-string (enum enum)
1957 :key (lambda (value)
1958 (stringify enum value)))))))
1963 Since enumerations allow their arguments to be abbreviated, a utility
1964 function named @code{closest-match} is used to find the closest match
1965 between an argument and the possible values. Otherwise, an
1966 @code{invalid-argument} error is raised. For an explanation of
1967 @code{stringify}, @xref{Value Stringification Protocol}.
1969 @node Error Management, Value Stringification Protocol, Argument Conversion Protocol, New Option Types
1970 @subsection Error Management
1972 @cindex Debugger restarts
1973 Let's take a short break in our @clon{} extension process. We have seen
1974 that @clon{} may throw errors in different situations, including invalid
1975 arguments or values. The end-user manual advertises that the interactive
1976 error handler offers a set of ``options to fix problems'' (if you don't
1977 know what I'm talking about, please read @enduserref{Error Management}
1978 and you will know). Well, you may have guessed that these options are
1979 simply ``restarts'' (of course, we don't use that term there, as we
1980 wouldn't want to frighten the casual user, or would we?).
1982 When you ship your application, you are encouraged to disable the
1983 debugger in the standalone executable because that also might scare the
1984 casual user a little bit (the end-user manual only mentions the
1985 @code{none} error-handler to explain that people shouldn't use it). The
1986 way error handling is done in @cl{} standalone executables is
1987 implementation-dependent, so please refer to your favorite compiler's
1988 documentation. More generally, the behavior of @cl{} standalone
1989 executables may depend on:
1993 the state of the Lisp environment when the application was dumped, which
1994 may in turn depend on @cmdline{} options passed to the Lisp itself
1995 (@pxref{Dumping Executables}),
1998 the arguments passed to the dumping function (look at @clon{}'s
1999 @code{dump} macro to see what it does),
2004 No, really, @cl{} is no fun at all.
2006 @node Value Stringification Protocol, Constructor Functions, Error Management, New Option Types
2007 @subsection Value Stringification Protocol
2008 Okay, back to implementing our new option type.
2010 @cindex Value Stringification Protocol
2011 @cindex Protocols, value stringification
2012 The third and last protocol we need to implement is called the
2013 @dfn{value stringification} protocol. This protocol can be seen as the
2014 reverse protocol for argument conversion (@pxref{Argument Conversion
2015 Protocol}): its purpose is to transform an option's value into a
2016 corresponding argument that the end-user could have provided in order to
2020 @cvopindex{:fallback-value}
2021 @cindex Values, source, fallback
2022 @cvopindex{:default-value}
2023 @cindex Values, source, default
2024 @gfmindex{convert,@r{Enumerations (}enum@r{)}}
2025 The main use for this protocol is to advertise the fallback and default
2026 values correctly in help strings: the end-user does not want to see
2027 those @emph{values}, but rather the @emph{argument} that would lead to
2028 them. However, you are free to use it wherever you like (see the
2029 @code{convert} method for @code{enum} options for instance).
2031 The value stringification protocol is implemented through a
2032 @code{stringify} generic function for which you must provide a method.
2034 @deffn {Generic Function} stringify OPTION VALUE
2035 @gfsubindex{stringify}
2036 Transform OPTION's @var{VALUE} into an argument.
2039 I admit that this function could also have been called
2040 @code{argumentize} or even @code{deconvertify}. As you can see, you need
2041 to provide a method with the first argument specialized to your new
2042 option type. You can assume that @var{VALUE} is a valid value for your
2043 option, so no checking is necessary and no error needs to be raised.
2045 @gfmindex{stringify,@r{Enumerations (}enum@r{)}}
2046 @voindex{Enumerations,enum}
2047 Let's look at the enumeration example now.
2051 (defmethod stringify ((enum enum) value)
2052 "Transform ENUM's VALUE into an argument."
2053 (string-downcase (symbol-name value)))
2057 Pretty straightforward, right?
2060 @node Constructor Functions, , Value Stringification Protocol, New Option Types
2061 @subsection Constructor Functions
2062 @cindex Constructors, for options objects
2063 @cindex Option Constructors
2064 The last required step to complete our new option type extension is to
2065 provide a @dfn{constructor} function that wraps around
2066 @code{make-instance} on the corresponding option class. I won't insult
2067 you by explaining how to write a constructor. Let me just give four good
2068 reasons why providing constructors is important.
2070 Providing a constructor for every new option type is important because:
2075 it is a good software engineering practice,
2081 and above all, it makes your new option type automatically available in
2082 calls to @code{defsynopsis} and @code{defgroup} (@pxref{Synopsis Items}
2083 and @ref{Group Definition}).
2087 @voindex{Enumerations,enum}
2089 Let's look at the enumeration example now.
2093 (defun make-enum (&rest keys
2094 &key short-name long-name description
2095 argument-name argument-type
2096 enum env-var fallback-value default-value
2098 "Make a new enum option.
2099 - SHORT-NAME is the option's short name (without the dash).
2101 - LONG-NAME is the option's long name (without the double-dash).
2103 - DESCRIPTION is the option's description appearing in help strings.
2105 - ARGUMENT-NAME is the option's argument name appearing in help strings.
2106 - ARGUMENT-TYPE is one of :required, :mandatory or :optional (:required and
2107 :mandatory are synonyms).
2108 It defaults to :optional.
2109 - ENUM is the set of possible values.
2110 - ENV-VAR is the option's associated environment variable.
2112 - FALLBACK-VALUE is the option's fallback value (for missing optional
2114 - DEFAULT-VALUE is the option's default value, if any.
2115 - When HIDDEN, the option doesn't appear in help strings."
2116 (declare (ignore short-name long-name description
2117 argument-name argument-type
2118 enum env-var fallback-value default-value
2120 (apply #'make-instance 'enum keys))
2124 Woah, what a mouthful for a single line of code@dots{} Yeah, I'm a
2125 maniac and I like redundancy. I always restate all the available keys
2126 explicitely, and everything again in the docstring so that all the
2127 interesting information is directly available (I might change my mind as
2128 I grow older though).
2134 @node Extension Tips, , New Option Types, Extending Clon
2135 @section Extension Tips
2136 So that's it. Now you know how to extend @clon{} with your own option
2137 types. Here is some piece of advice that you might find useful in the
2141 * Incremental Option Types:: Doing without defoption
2142 * Lisp Option Abuse:: Thinking in end-user terms
2145 @node Incremental Option Types, Lisp Option Abuse, Extension Tips, Extension Tips
2146 @subsection Incremental Option Types
2148 If one of the built-in options is almost what you need, you may be
2149 tempted to subclass it directly instead of using @code{defoption}, and
2150 only change what's needed, After all, it's Lisp. Lisp is a world of
2151 mess@t{^D^D^D^D}freedom.
2157 @code{defoption} is not @emph{only} a convenience wrapper around
2158 @code{defclass}. It also arranges for @code{defsynopsis} and
2159 @code{defgroup} to recognize your new option type. So please, do use it
2162 @node Lisp Option Abuse, , Incremental Option Types, Extension Tips
2163 @subsection Lisp Option Abuse
2164 @voindex{Lisp Objects,lispobj}
2165 @vopindex{Lisp Objects,lispobj,:typespec}
2166 Along with the same lines, you may find that the @code{lispobj} type is
2167 all you need in many situations. Let's take an example. Suppose you want
2168 to implement a @code{--stars} option to assign a rank to a movie, from 0
2169 to 5. The lazy approach is to simply create a @code{lispobj} option with
2170 a @code{:typespec} (type specifier) of @code{(integer 0 5)} and you're
2173 But now, remember that the end-user of your application is probably not
2174 a Lisper (in fact, I would hope that @clon{} contributes to increasing
2175 the number of standalone @cl{} applications out there@dots{}). What do
2176 you think would be her reaction, if, after providing a bogus value to
2177 the @code{--stars} option, she get the following error message:
2180 Option 'stars': invalid argument "6".
2181 Argument "6" must evaluate to (integer 0 5).
2184 or worse, a @code{"Cannot parse argument"} error message because of a
2187 Not very friendly, right? In other words, you need to think in terms of
2188 what the end-user of your application will expect. In that particular
2189 situation, you might want to subclass @code{lispobj} (with
2190 @code{defoption}!) only to provide friendlier error messages.
2194 @c ====================================================================
2196 @c ====================================================================
2197 @node Advanced Usage, Conclusion, Extending Clon, Top
2198 @chapter Advanced Usage
2200 This chapter contains information about different features that are
2201 present in @clon{} because of design decisions, but that I expect to be
2202 used only rarely, if at all.
2205 * Multiple Clon Instances:: Different command-lines, synopsis or contexts
2206 * Programmatic Help Strings:: Beyond the --help option
2207 * Version Numbering:: In case you need to conditionalize
2211 @c -----------------------
2212 @c Multiple Clon Instances
2213 @c -----------------------
2214 @node Multiple Clon Instances, Programmatic Help Strings, Advanced Usage, Advanced Usage
2215 @section Multiple @clon{} Instances
2217 It is possible to use different instances of @clon{} in parallel in a
2218 single application, by using a virtual @cmdline{} instead of the real
2219 one, different synopsis and multiple contexts simultaneously.
2222 * Using Different Synopsis:: The default one, and the others
2223 * Using Different Command-Lines:: The real one, and the others
2224 * Using Multiple Contexts:: The current one, and the others
2225 * Potential Uses:: What to do with all that
2228 @node Using Different Synopsis, Using Different Command-Lines, Multiple Clon Instances, Multiple Clon Instances
2229 @subsection Using Different Synopsis
2230 @cindex Synopsis, default
2231 Did you notice that after defining a synopsis, there is actually never
2232 any explicit reference to it anymore? So where is the magick? In fact,
2233 there's no magick at all involved here.
2236 @foindex{defsynopsis,:make-default}
2237 @cfiaindex{make-synopsis,:make-default}
2238 @clon{} has a global variable named @code{*synopsis*} which holds the
2239 current synopsis. When you define/create a synopsis with either
2240 @code{defsynopsis} or @code{make-synopsis}, it is automatically made the
2241 default one, unless you use the @code{:make-default} option/initarg with
2242 a value of @code{nil}, like this:
2245 (defsynopsis (:make-default nil) ...)
2251 (make-synopsis :make-default nil ...)
2254 @cfindex{make-context}
2255 When you create a context with @code{make-context}, the default synopsis
2256 is used implicitely, but you have two ways to avoid this.
2261 At any time in your program, you may change the value of
2262 @code{*synopsis*}. All subsequent calls to @code{make-context} will
2263 hence use this other synopsis.
2265 @cfiaindex{make-context,:synopsis}@c
2266 If you prefer to use another synopsis only temporarily, you can use the
2267 @code{:synopsis} initarg to @code{make-context} instead.
2270 @node Using Different Command-Lines, Using Multiple Contexts, Using Different Synopsis, Multiple Clon Instances
2271 @subsection Using Different Command-Lines
2272 In @ref{Context Creation}, we saw that a context object describes a
2273 particular instance of your application, most notably depending on the
2274 actual @cmdline{} the end-user provided. It turns out, however that the
2275 @cmdline{} doesn't need to be the actual program's @cmdline{}, as the
2276 user typed it. Any list of strings can act as a @cmdline{}.
2278 @cfiaindex{make-context,:cmdline}
2279 The function @code{make-context} has a @code{:cmdline} key that allows
2280 you to provide any list of strings that will act as the @cmdline{}. Of
2281 course, the default is to use the actual program's one.
2283 @node Using Multiple Contexts, Potential Uses, Using Different Command-Lines, Multiple Clon Instances
2284 @subsection Using Multiple Contexts
2285 @cindex Context, current
2286 Did you also notice that after creating a context, there is actually
2287 never any explicit reference to it anymore? So again, where is the
2288 magick? In fact, there's no magick at all involved here either.
2291 @cfiaindex{make-context,:make-current}@c
2292 @clon{} has a global variable named @code{*context*} which holds the
2293 current context. When you create a context with @code{make-context}, it
2294 is automatically made current, unless you use the @code{:make-current}
2295 initarg with a value of @code{nil}.
2297 @cindex Runtime Phase
2300 @findex cmdline-options-p
2303 @findex getopt-cmdline
2304 @findex multiple-value-getopt-cmdline
2305 @findex do-cmdline-options
2307 The whole runtime phase API of @clon{} uses a context implicitely. This
2308 involves @code{progname}, @code{remainder}, @code{cmdline-options-p},
2309 @code{cmdline-p}, @code{getopt}, @code{getopt-cmdline},
2310 @code{multiple-value-getopt-cmdline}, @code{do-cmdline-options} and
2311 @code{help}. As a consequence, it is possible to use @clon{} with
2312 multiple contexts at the same time. There are in fact three ways to
2318 At any time in your program, you may change the value of
2319 @code{*context*}. All subsequent calls to the runtime phase API
2320 will hence use this other context.
2322 @clon{} also provides a macro which changes the current context for you.
2323 @defun with-context CONTEXT &body BODY
2324 Execute @var{BODY} with @code{*context*} bound to @var{CONTEXT}.
2327 @fkindex{progname,:context}@c
2328 @fkindex{remainder,:context}@c
2329 @fkindex{cmdline-options-p,:context}@c
2330 @fkindex{cmdline-p,:context}@c
2331 @fkindex{getopt,:context}@c
2332 @fkindex{getopt-cmdline,:context}@c
2333 @fkindex{help,:context}@c
2334 @foindex{multiple-value-getopt-cmdline,:context}@c
2335 @foindex{do-cmdline-options,:context}@c
2336 If you prefer to use another context only once, you can use the
2337 @code{:context} key instead. The whole runtime phase API of @clon{}
2338 understands it. For the functions @code{getopt}, @code{getopt-cmdline}
2339 and @code{help}, it's just another key in addition to those we've
2340 already seen. For the macros @code{multiple-value-getopt-cmdline} and
2341 @code{do-cmdline-options}, the key must appear at the end of the first
2342 (list) argument, like this:
2345 (multiple-value-getopt-cmdline (option name value :context ctx) ...)
2346 (do-cmdline-options (option name value :context ctx) ...)
2350 @node Potential Uses, , Using Multiple Contexts, Multiple Clon Instances
2351 @subsection Potential Uses
2352 By combining @clon{}'s ability to use a virtual @cmdline{}, different
2353 synopsis and multiple contexts, you can achieve very neat (read: totally
2354 useless) things. For instance, you could write an application that takes
2355 an option providing @cmdline{} arguments for an external program to be
2356 forked. Some revision control systems do that for controlling external
2357 @code{diff} programs for instance, so no big deal. The big deal is that
2358 you can completely control the validity of the external program's
2359 @cmdline{}, before it is forked, from your original one.
2361 Here is another idea, again related to revision control systems. Some of
2362 them feature a @cmdline{} syntax like the following:
2365 prog [global options] command [command-specific options]
2369 @cindex Command-Line, remainder
2370 @cindex Remainder, of command-line
2371 You can achieve this with @clon{} quite easily. In fact, the
2372 demonstration program called @file{advanced} in the distribution shows
2373 you how to do it. First, define a synopsis which only handles the global
2374 options, and provide a postfix of @code{"command [command-specific
2375 option]"} or something like that. This will authorize a @cmdline{}
2376 remainder which will start with the command name.
2378 Now, for every command in your program, define a specific synopsis with
2379 only the command-specific options. Get the remainder of the original
2380 @cmdline{} (@pxref{Command-Line Remainder}) and figure out which command
2381 was used. Depending on it, create a new context with the appropriate
2382 synopsis and the original @cmdline{}'s remainder as the new, virtual,
2383 @cmdline{}. You're done: retrieve global options from the first context,
2384 and command-specific ones from the second one.
2386 @cindex Help String, display
2388 What's even cooler is that you can display the command-specific options
2389 on demand quite easily as well (like what @file{git} does when you call
2390 it like this: @code{git commit --help} for instance): calling the
2391 @code{help} function on the original context gives you the global
2392 options's help string while calling it on the command-specific one will
2393 display the command-specific usage.
2395 @bioindex{search-path}
2396 @bievindex{SEARCH_PATH}
2397 @bioindex{highlight}
2398 @bievindex{HIGHLIGHT}
2401 @bioindex{line-width}
2402 @bievindex{LINE_WIDTH}
2403 One thing to remember here is that every context/synopsis duet you
2404 create gets its own set of built-in @clon{} options. As a consequence,
2405 there is currently no simple way to have a single set of built-in
2406 options apply to the whole application, for instance, to both a global
2407 and a command-specific context. Let me make this clearer: if your
2408 end-user calls @code{prog --clon-theme=foo command -h}, then the theme
2409 option will have no effect because it would only affect the global help
2410 option. In order to actually use the expected theme, your end-user would
2411 need to use @code{prog command --clon-theme=foo -h}. Depending on which
2412 cerebral emisphere (s)he prefers to use, this may seem logical or not.
2414 Finally, note that you can use the virtual @cmdline{} / specific
2415 synopsis technique recursively to manage complicated @cmdline{} syntax,
2416 for instance alternating options and non-options parts several times.
2418 In the future, @clon{} may provide better ways to achieve this kind of
2419 things (a notion of ``sub-context'' may be in order).
2423 @c -------------------------
2424 @c Programmatic Help Strings
2425 @c -------------------------
2426 @node Programmatic Help Strings, Version Numbering, Multiple Clon Instances, Advanced Usage
2427 @section Programmatic Help Strings
2432 @cindex Themes, standard, @t{refcard}
2433 @cindex Standard Themes, @t{refcard}
2434 So far, we've seen how to use the @code{help} function to implement a
2435 typical @code{--help} option. This is mostly intended for the end-user.
2436 There are also times when this function could be useful to @emph{you},
2437 the application developer. For instance, one could imagine that part of
2438 the compilation phase would involve generating the help string in order
2439 to include it in the manual. Another idea would be that @samp{make
2440 install} creates a @file{REFCARD} file in
2441 @file{/usr/local/share/doc/my-app/} which contains the help string
2442 formatted with the @code{refcard} theme, @etc{}.
2446 @bioindex{search-path}
2447 @bievindex{SEARCH_PATH}
2448 @bioindex{line-width}
2449 @bievindex{LINE_WIDTH}
2450 @bioindex{highlight}
2451 @bievindex{HIGHLIGHT}
2452 In such situations, calling the @code{help} function might not be
2453 directly associated with an end-user level option, or at least not
2454 @code{--help}, and you might not want to honor the end-user level
2455 settings for theme, search path, line-width, or highlighting either
2456 (remember that these settings might come from the environment variables
2457 associated with @bioption{theme}, @bioption{search-path},
2458 @bioption{line-width} and @bioption{highlight}).
2460 @fkindex{help,:theme}
2461 @fkindex{help,:search-path}
2462 @fkindex{help,:line-width}
2463 @fkindex{help,:highlight}
2464 Because of this, the @code{help} function provides additional keys that
2465 allow you to override those settings (they are in fact stored in the
2466 context object). The keys in question are: @code{:theme},
2467 @code{:search-path}, @code{:line-width} and @code{:highlight}.
2469 @fkindex{help,:output-stream}
2470 @vindex *standard-output*
2471 In addition to that, there is an @code{:output-stream} key which
2472 defaults to @code{*standard-output*} which you could use for instance to
2473 write directly to a file. Note that there is no end-user level access to
2478 @c -----------------
2479 @c Version Numbering
2480 @c -----------------
2481 @node Version Numbering, , Programmatic Help Strings, Advanced Usage
2482 @section Version Numbering
2485 As @clon{} evolves over time, you might one day feel the need for
2486 conditionalizing your code on the version of the library. While the
2487 end-user of your application has limited means to access the current
2488 version number of @clon{} (see @enduserref{Clonification} and the
2489 built-in option @bioption{version}), you, the application programmer
2490 and @clon{} user, have a finer grained access to it.
2492 The first thing you can do to access the current version number of
2493 @clon{} is use the @code{version} function (this is in fact the function
2494 bound to the @bioption{version} option).
2496 @defun version &optional (TYPE :number)
2497 Return the current version number of @clon{}. @var{TYPE} can be one of
2498 @code{:number}, @code{:short} or @code{:long}. For @code{:number}, the
2499 returned value is a fixnum. Otherwise, it is a string.
2502 A @clon{} version is characterized by 4 elements as described below.
2505 @vindex +release-major-level+
2506 A major version number stored in the constant
2507 @code{+release-major-level+}.
2509 @vindex +release-minor-level+
2510 A minor version number, stored in the constant
2511 @code{+release-minor-level+}.
2513 @vindex +release-status+
2514 A release status stored in the constant @code{+release-status+}. The
2515 status of a release can be @code{:alpha}, @code{:beta}, @code{:rc}
2516 (standing for ``release candidate'') or @code{:patchlevel}. These are in
2517 effect 4 levels of expected stability.
2519 @vindex +release-status-level+
2520 A status-specific version number stored in the constant
2521 @code{+release-status-level+}. Status levels start at 1 (alpha 1, beta 1
2522 and release candidate 1) except for stable versions, in which case patch
2523 levels start at 0 (@eg{} 2.4.0).
2526 @vindex +release-name+
2527 In addition to that, each version of @clon{} (in the sense
2528 @emph{major.minor}, regardless of the status) has a name, stored in the
2529 constant @code{+release-name+}. The general theme for @clon{} is ``Great
2530 Jazz Musicians'', and specifically for the 1.x series: ``Great Saxophone
2531 Players''. Anyone daring to mention Kenny G at that point will be shot
2534 Here is how the @code{version} function computes its value.
2537 A version @code{:number} is computed as @emph{major . 10000 + minor .
2538 100 + patchlevel}, effectively leaving two digits for each level. Note
2539 that alpha, beta and release candidate status are ignored in version
2540 numbers (this is as if the corresponding status level was considered to
2541 be always 0). Only stable releases have their level taken into account.
2543 A @code{:short} version will appear like this for unstable releases:
2544 1.3a4, 2.5b8 or 4.2rc1. Remember that alpha, beta or release candidate
2545 levels start at 1. Patchlevels for stable releases start at 0 but 0 is
2546 ignored in the output. So for instance, version 4.3.2 will appear as-is,
2547 while version 1.3.0 will appear as just 1.3.
2549 A @code{:long} version is expanded from the short one, and includes the
2550 release name. For instance, 1.3 alpha 4 "Bill Evans", 2.5 beta 8 "Scott
2551 Henderson", 4.2 release candidate 1 "Herbie Hancock" or 4.3.2 "Chick
2552 Corea". As for the short version, a patchlevel of 0 is ignored in the
2553 output: 1.3 "Bill Evans".
2558 @c ====================================================================
2560 @c ====================================================================
2561 @node Conclusion, Technical Notes, Advanced Usage, Top
2564 So that's it I guess. You know all about @clon{} now. The next step is
2565 to actually use it to clonify your favorite application, write new
2566 applications using it and contaminate the world with standalone @cl{}
2567 programs, featuring unprecedented @cmdline{} power and thrill-a-minute
2570 Now, go Luke. The Attack of the @clon{} is ready to begin.
2574 @c ====================================================================
2576 @c ====================================================================
2577 @node Technical Notes, API Quick Reference, Conclusion, Top
2578 @appendix Technical Notes
2580 This chapter contains important information about the library's
2581 configuration, supported platforms, non-ANSI features and
2582 portability concerns.
2585 * Configuration:: Pre-loading parameters
2586 * Non-ANSI Features:: Requiring operating system access
2587 * Supported Platforms:: Systems, compilers and dependencies
2588 * Dumping Executables:: Convenience wrappers
2589 * Not Dumping Executables:: Using Clon interactively
2596 @node Configuration, Non-ANSI Features, Technical Notes, Technical Notes
2597 @section Configuration
2598 @cindex Configuration
2599 @vindex com.dvlsoft.clon.configuration
2600 Some aspects of @clon{}'s behavior can be configured @emph{before} the
2601 ASDF system is actually loaded. @clon{} looks for configuration options
2602 in a variable called @code{com.dvlsoft.clon.configuration} in the
2603 @code{cl-user} package. If set, this variable should contain a property
2604 list of configuration options and their corresponding values. Currently,
2605 the following options are provided.
2608 @item :swank-eval-in-emacs
2609 @coindex{swank-eval-in-emacs}@c
2610 @vindex slime-enable-evaluate-in-emacs
2611 This option is only useful if you use Slime, and mostly if you plan on
2612 hacking @clon{} itself. The library provides indentation information for
2613 some of its functions directly embedded in the code. This information
2614 can be automatically transmitted to (X)Emacs when the ASDF system is
2615 loaded if you set this option to @code{t}. However, note that for this
2616 to work, the Slime variable @code{slime-enable-evaluate-in-emacs} must
2617 also be set to @code{t} in your (X)Emacs session. If you're interested
2618 to know how this process works, I have described it in the following
2620 @uref{http://www.didierverna.com/sciblog/index.php?post/2011/07/20/One-more-indentation-hack}.
2622 @coindex{restricted}@c
2623 @cindex Restricted Mode
2624 Some non-ANSI features of @clon{} require external functionality that
2625 may not be available in all contexts. Normally, @clon{} should
2626 autodetect this and switch to so-called @emph{restricted mode} at
2627 build-time (@pxref{Non-ANSI Features}). If @clon{} has failed to
2628 autodetect the problem (in which case I would like to know), or if for
2629 some reason, you explicitly want to disable those features, you may set
2630 the @code{:restricted} configuration option to @code{t}.
2633 This option is only used by the ABCL port. @ref{Dumping Executables},
2634 provides more information on its use.
2638 @c -----------------
2639 @c Non-ANSI Features
2640 @c -----------------
2641 @node Non-ANSI Features, Supported Platforms, Configuration, Technical Notes
2642 @section Non-ANSI Features
2643 One feature of @clon{} that is beyond the ANSI standard is terminal
2644 autodetection (it requires an @code{ioctl} call and hence a foreign
2645 function interface). Terminal autodetection is used in several
2646 situations, for turning on highlighting automatically and for detecting
2647 a terminal line width.
2649 @cindex Restricted Mode
2650 If, for some reason, terminal autodetection is not available, @clon{}
2651 will work in so-called @emph{restricted mode}. This means that
2652 @bioption{highlight=auto} won't work (highlighting will @emph{not} be
2653 turned on automatically on a @tty{}). For the same reason, unless
2654 otherwise specified via either the @code{COLUMNS} environment variable
2655 or the @bioption{line-width} option, terminal output will be formatted
2656 for 80 columns regardless of the actual terminal width
2657 (@pxenduserref{Global Control}).
2660 @c ----------------------
2661 @c Supported Platforms
2662 @c ----------------------
2663 @node Supported Platforms, Dumping Executables, Non-ANSI Features, Technical Notes
2664 @section Supported Platforms
2665 @clon{} currently works on Unix (including MacOS X) and Windows (Cygwin
2666 or MinGW) and has been ported to 8 @cl{} implementations. The following
2667 table lists the supported platforms.
2669 @multitable {Compiler} {Minimum Version} {@code{cffi} (optional)}
2670 @headitem Compiler @tab Minimum Version @tab Dependencies
2681 @tab 11.1.2@footnote{more precisely, git revision
2682 3e2e5f9dc3c5176ef6ef8d7794bfa43f1af8f8db}
2686 @tab @code{cffi} (optional)
2688 @tab 0.24.0@footnote{more precisely, svn trunk revision 13156}
2690 @item Allegro@footnote{both standard and modern images are supported}
2692 @tab @code{cffi} (optional)
2695 @tab @code{cffi} (optional)
2698 @unnumberedsubsec CLISP, Allegro and LispWorks specificities
2699 @cindex Restricted Mode
2700 As mentioned in the above table, CLISP, Allegro and LispWorks dependency
2701 on @code{cffi} is optional. They need @code{cffi} in order to implement
2702 terminal autodetection only (note that many other implementations come
2703 with their own foreign function interface). If @code{cffi} cannot be
2704 found when the ASDF system is loaded (or in the case of CLISP, if it has
2705 been compiled without @code{ffi} support), you get a big red blinking
2706 light and a warning but that's all. @clon{} will still work, although in
2709 @unnumberedsubsec ABCL specificities
2710 @clon{}'s ABCL port currently has two limitations:
2713 @bioindex{highlight}@c
2714 @bioindex{line-width}@c
2716 @cindex Restricted Mode
2717 It only works in restricted mode (@pxref{Non-ANSI Features}).
2719 Since Java doesn't have a @code{putenv} or @code{setenv} function (!!),
2720 the @code{modify-environment} restart, normally proposed when an
2721 environment variable is set to a bogus value, is unavailable
2722 (@pxenduserref{Error Management}).
2726 @c -------------------
2727 @c Dumping Executables
2728 @c -------------------
2729 @node Dumping Executables, Not Dumping Executables, Supported Platforms, Technical Notes
2730 @section Dumping Executables
2732 Creating standalone executables is orthogonal to @clon{}. @clon{} is
2733 just a library that you might want to use, and in fact, it is also
2734 possible to use it without dumping executables at all (@pxref{Not
2735 Dumping Executables}).
2739 Unfortunately, there is no standard way to dump executables from Lisp.
2740 We're entering the portability mine field here. @clon{}, however, wants
2741 to help. We've already seen that it provides utility wrappers like
2742 @code{exit} and @code{dump} to make your life easier (I mean, more
2743 portable) in @ref{Quick Start}. If you're not interested in portability
2744 or if you prefer to do it your own way, you don't @emph{need} to use
2745 those wrappers. If you do, however, please read on.
2747 Continuing on the quickstart example, the table below provides
2748 ready-to-use @cmdline{} samples for dumping the program with the
2749 compilers currently supported. Remember that they work in conjunction
2750 with the somewhat rudimentary @code{dump} macro mentionned above.
2754 @code{CC=gcc sbcl --script quickstart.lisp}@*
2755 The @code{CC=gcc} bit is needed for the @code{sb-grovel} contrib module
2756 that @clon{} uses (unless restricted mode is requested).
2758 @code{lisp -noinit -nositeinit -load quickstart.lisp}
2760 @code{ccl --no-init --load quickstart.lisp}
2762 ECL doesn't work like the other Lisp compilers. In particular, creating
2763 an executable does not involve dumping a Lisp image, but compiling the
2764 source into separate object files and then linking them. The consequence
2765 is that there is no simple @cmdline{} recipe to show here. Instead, you
2766 might want to look at the file @file{demos/dump.lisp} in the
2767 distribution for an example. Note that this file doesn't really attempt
2768 to dump the whole application. Only the actual example file is dumped.
2770 Because the dumping scheme is different with ECL, it is also less
2771 straightforward to write portable code for standalone applications. The
2772 demo programs in the distribution both contain comments that are worth
2773 reading at the top of them.
2776 One specific difference between ECL and the other Lisp compilers is that
2777 it doesn't require you to specify a particular function as the entry
2778 point for your executable, but instead relies on having code to execute
2779 directly at the toplevel of some file. @clon{}'s @code{dump} macro helps
2780 you with this: it normally expands to a compiler-specific function which
2781 saves the current Lisp image, but for ECL, it simply expands to the
2782 ``main'' function call, hence consituting the entry point to the code
2785 @code{CC=gcc clisp -norc -i quickstart.lisp}@*
2786 The @code{CC=gcc} bit lets you choose your preferred C compiler for
2787 @code{cffi}. Please note that executables dumped (the @clon{} way) by
2788 CLISP still understand lisp-specific @cmdline{} options when they are
2789 prefixed with @code{--clisp-}, so you should obviously avoid defining
2790 options by those names.
2792 ABCL is a totally different beast because it's a Java-based @cl{}
2793 implementation. Most notably, you don't create standalone executables in
2794 Java, so the normal way of running ABCL is by telling it to load some
2795 lisp code. If you want to run the quickstart program in the usual way,
2796 you will typically type this:
2798 abcl --noinform --noinit --nosystem --load quickstart.lisp
2800 Note that for this to work, the @code{dump} macro expands to the
2801 ``main'' function call for ABCL, just as for ECL.
2803 There's more to it than that though. It is possible to get closer to
2804 standalone executables with ABCL by 1/ providing your whole application
2805 in a @code{jar} file directly, and 2/ overriding ABCL's entry point by
2806 providing your own interpreter which runs your main function
2807 automatically. I have described this process in more details in the
2808 following blog entry:
2809 @uref{http://www.didierverna.com/sciblog/index.php?post/2011/01/22/Towards-ABCL-Standalone-Executables}.
2812 @clon{} helps you to do this to some extend. If the @code{:dump}
2813 configuration option is set (@pxref{Configuration}), then the
2814 @code{dump} macro doesn't expand to a call to the ``main'' function, but
2815 instead dumps a Java file containing an alternate ABCL interpreter that
2816 you can compile and add to the original ABCL @code{jar} file, along with
2817 @file{quickstart.lisp}. If you want more details on this, you will need
2818 to look at the @file{Makefile} in the @code{demo} directory and also at
2819 the file @file{Makefile.inc} at the toplevel.
2822 Dumping a complete application with Allegro is complicated, but more
2823 importantly only possible in the Enterprise edition. Because of that,
2824 @clon{}'s dumping facility only makes use of the @code{dumplisp} feature
2825 which just dumps a Lisp image. You can perform this operation with a
2826 @cmdline{} such as @samp{alisp -qq -L quickstart.lisp}. The Makefile
2827 infrastructure in the @file{demo} directory also creates shell script
2828 wrappers around this image to simplify their use.
2830 @code{lispworks -init - -siteinit - -load quickstart.lisp}@*
2831 Please note that dumping a complete application with LispWorks is only
2832 possible in the Professional or Enterprise editions.
2836 @c -----------------------
2837 @c Not Dumping Executables
2838 @c -----------------------
2839 @node Not Dumping Executables, , Dumping Executables, Technical Notes
2840 @section Not Dumping Executables
2841 Although @cmdline{} processing really makes sense for standalone
2842 executables, you may want to preserve interactivity with your
2843 application during the development phase, for instance for testing or
2846 It is possible to use @clon{} interactively, that is, within a regular
2847 Lisp REPL, without dumping anything. First of all, we have already seen
2848 that it is possible to use a virtual @cmdline{} (@pxref{Using Different
2849 Command-Lines}). You can also use @clon{} interactively with the actual
2850 Lisp invocation's @cmdline{}, although a word of advice is in order
2855 As you might expect, the problem in that situation lies in the way the
2856 different Lisp implementations treat their own @cmdline{}. Guess what,
2857 it's a mess. When you dump an executable the @clon{} way, the
2858 @code{cmdline} function will always contain user options only (the
2859 @code{dump} macro instructs the compilers to @emph{not} process the
2860 @cmdline{} at all). When you use @clon{} interactively and mix
2861 compiler-specific options with application ones when invoking your Lisp
2862 environment, the situation is as follows:
2866 SBCL processes its own options and leaves the others unprocessed on the
2867 @cmdline{}. This means that as long as there is no overlap between
2868 SBCL's options and yours, you can just put them all together on the
2869 @cmdline{}. In case of overlap however, you need to separate SBCL's
2870 options from yours with a call to @code{--end-toplevel-options} (that's
2871 an SBCL specific option separator).
2873 @cindex Command-Line, remainder
2874 @cindex Remainder, of command-line
2875 CMUCL processes its own options, issues a warning about the options it
2876 doesn't know about, but in any case, it eats the whole @cmdline{}.
2877 Consequently, if you want to provide options to your application, you
2878 need to put them after a @code{--} separator. Note that you can still
2879 use a second such separator to provide @clon{} with both some options
2880 and a remainder (@pxenduserref{Option Separator}).
2884 CCL, ECL and CLISP all process their own options but will abort on
2885 unknown ones. Consequently, if you want to provide options to your
2886 application, you need to put them after a @code{--} separator. Note that
2887 you can still use a second such separator to provide @clon{} with both
2888 some options and a remainder (@pxenduserref{Option Separator}).
2890 ABCL processes its own options and leaves the others unprocessed on the
2891 @cmdline{}. This means that as long as there is no overlap between
2892 ABCL's options and yours, you can just put them all together on the
2893 @cmdline{}. In case of overlap however, you need to separate ABCL's
2894 options from yours with 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}).
2898 Allegro processes its own options, issues only a warning about options
2899 it doesn't know of, and leaves anything after a @code{--} alone.
2900 Consequently, if you want to provide options to your application, you
2901 need to put them after a @code{--} separator. Note that you can still
2902 use a second such separator to provide @clon{} with both some options
2903 and a remainder (@pxenduserref{Option Separator}).
2905 LispWorks processes its own options and ignores the other ones, but
2906 always leaves everything on the command-line. It does not currently
2907 support @code{--} as an option separator either. Consequently, if you
2908 want to provide options to your application, you need to put them after
2909 a @code{--} separator, although you @emph{will} get into trouble if any
2910 option there is recognized by LispWorks itself. 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}).
2917 @c ====================================================================
2918 @c API Quick Reference
2919 @c ====================================================================
2920 @node API Quick Reference, Indexes, Technical Notes, Top
2921 @appendix API Quick Reference
2924 * Utilities:: Miscellaneous stuff
2925 * Initialization Phase API:: Synopsis, items and context creation
2926 * Runtime Phase API:: Option retrieval and help formatting
2927 * Extension API:: New option types
2928 * Versioning API:: Release identification
2935 @node Utilities, Initialization Phase API, API Quick Reference, API Quick Reference
2938 @defmac dump NAME FUNCTION
2939 See @ref{Quick Start}.
2942 @defun exit &optional (STATUS 0)
2943 See @ref{Quick Start}.
2946 @cindex Command-Line
2948 See @ref{Option Retrieval}.
2951 @cindex Package, nicknames
2952 @defun nickname-package &optional NICKNAME
2953 See @ref{Quick Start}.
2957 @c ------------------------
2958 @c Initialization Phase API
2959 @c ------------------------
2960 @node Initialization Phase API, Runtime Phase API, Utilities, API Quick Reference
2961 @section Initialization Phase API
2963 @defun make-text &key CONTENTS HIDDEN
2964 @cfsubindex{make-text}
2965 @cfiaindex{make-text,:contents}
2966 @cfiaindex{make-text,:hidden}
2967 @defunx make-@var{OPTION} :INITARG INITVAL@dots{}
2968 @cfsubindex{make-@var{OPTION}}
2970 @cfindex make-stropt
2971 @cfindex make-lispobj
2974 @cfindex make-switch
2975 @cfindex make-xswitch
2976 @defunx make-group &key HEADER HIDDEN ITEM
2977 @cfsubindex{make-group}
2978 @cfiaindex{make-group,:header}
2979 @cfiaindex{make-group,:hidden}
2980 @cfiaindex{make-group,:item}
2981 @defunx make-synopsis &key POSTFIX ITEM (MAKE-DEFAULT t)
2982 @cfsubindex{make-synopsis}
2983 @cfiaindex{make-synopsis,:postfix}
2984 @cfiaindex{make-synopsis,:item}
2985 @cfiaindex{make-synopsis,:make-default}
2986 See @ref{Constructors} and @ref{Using Different Synopsis}.
2989 @defmac defgroup (&key HEADER HIDDEN) &body FORMS
2990 @foindex{defgroup,:header}
2991 @foindex{defgroup,:hidden}
2992 @xref{Group Definition}.
2995 @defmac defsynopsis (&key POSTFIX MAKE-DEFAULT) &body FORMS
2996 @foindex{defsynopsis,:postfix}
2997 @foindex{defsynopsis,:make-default}
2998 @fiindex{defsynopsis,text}
2999 @fiindex{defsynopsis,options}
3000 @fiindex{defsynopsis,group}
3001 See @ref{Synopsis Definition} and @ref{Using Different Synopsis}.
3005 @xref{Using Different Synopsis}.
3008 @defun make-context &key (SYNOPSIS *synopsis*) CMDLINE @
3010 @cfsubindex{make-context}
3011 @cfiaindex{make-context,:synopsis}
3012 @cfiaindex{make-context,:cmdline}
3013 @cfiaindex{make-context,:make-current}
3014 @xref{Context Creation}, @ref{Using Different Synopsis} and @ref{Using
3015 Different Command-Lines}.
3020 @c -----------------
3021 @c Runtime Phase API
3022 @c -----------------
3023 @node Runtime Phase API, Extension API, Initialization Phase API, API Quick Reference
3024 @section Runtime Phase API
3027 @xref{Using Multiple Contexts}.
3030 @defun with-context CONTEXT &body BODY
3031 @xref{Using Multiple Contexts}.
3034 @defun progname &key (CONTEXT *context*)
3035 @fkindex{progname,:context}
3036 See @ref{Contextual Information} and @ref{Using Multiple Contexts}.
3039 @defun remainder &key (CONTEXT *context*)
3040 @fkindex{remainder,:context}
3041 See @ref{Contextual Information} and @ref{Using Multiple Contexts}.
3044 @defun cmdline-options-p &key (CONTEXT *context*)
3045 @fkindex{cmdline-options-p,:context}
3046 See @ref{Command-Line Polling} and @ref{Using Multiple Contexts}.
3049 @defun cmdline-p &key (CONTEXT *context*)
3050 @fkindex{cmdline-p,:context}
3051 See @ref{Command-Line Polling} and @ref{Using Multiple Contexts}.
3054 @defun getopt &key (CONTEXT *context*) SHORT-NAME LONG-NAME @
3056 @fkindex{getopt,:context}
3057 @fkindex{getopt,:short-name}
3058 @fkindex{getopt,:long-name}
3059 @fkindex{getopt,:option}
3061 See @ref{Explicit Retrieval} and @ref{Using Multiple Contexts}.
3064 @defun getopt-cmdline &key (CONTEXT *context*)
3065 @fkindex{getopt-cmdline,:context}
3067 See @ref{Sequential Retrieval} and @ref{Using Multiple Contexts}.
3070 @defmac multiple-value-getopt-cmdline (OPTION NAME VALUE SOURCE &key CONTEXT) @
3072 @defmacx do-cmdline-options (OPTION NAME VALUE SOURCE &key CONTEXT) @
3074 @foindex{multiple-value-getopt-cmdline,:context}
3075 @foindex{do-cmdline-options,:context}
3076 See @ref{Sequential Retrieval} and @ref{Using Multiple Contexts}.
3079 @deffn Reader short-name OPTION
3080 @rfsubindex{short-name}
3081 @deffnx Reader long-name OPTION
3082 @rfsubindex long-name
3083 @xref{Sequential Retrieval}.
3086 @defun help &key (CONTEXT *context*) @
3087 (ITEM (synopsis context)) @
3088 (OUTPUT-STREAM *standard-output*) @
3089 (SEARCH-PATH (search-path context)) @
3090 (THEME (theme context)) @
3091 (LINE-WIDTH (line-width context)) @
3092 (HIGHLIGHT (highlight context)))
3093 @fkindex{help,:context}
3094 @fkindex{help,:item}
3095 @fkindex{help,:output-stream}
3096 @fkindex{help,:theme}
3097 @fkindex{help,:search-path}
3098 @fkindex{help,:line-width}
3099 @fkindex{help,:highlight}
3101 @vindex *standard-output*
3102 @xref{Help}, @ref{Using Multiple Contexts} and @ref{Programmatic Help
3110 @node Extension API, Versioning API, Runtime Phase API, API Quick Reference
3111 @section Extension API
3113 @defmac defoption CLASS SUPERCLASSES SLOTS &rest OPTIONS
3114 @pxref{New Option Classes}
3117 @deffn {Generic Function} check OPTION VALUE
3119 @xref{Value Check Protocol}.
3122 @deftp {Error Condition} option-error OPTION
3123 @ecsubindex{option-error}
3124 @ecsindex{option-error,option}
3125 @deftpx {Error Condition} invalid-value VALUE COMMENT
3126 @ecsubindex{invalid-value}
3127 @ecsindex{invalid-value,value}
3128 @ecsindex{invalid-value,comment}
3129 @xref{Value Check Protocol}.
3132 @deffn {Generic Function} convert OPTION ARGUMENT
3133 @gfsubindex{convert}
3134 @xref{Argument Conversion Protocol}.
3137 @deftp {Error Condition} invalid-argument ARGUMENT COMMENT
3138 @ecsubindex{invalid-argument}
3139 @ecsindex{invalid-argument,argument}
3140 @ecsindex{invalid-argument,comment}
3141 @xref{Argument Conversion Protocol}.
3144 @deffn {Generic Function} stringify OPTION VALUE
3145 @gfsubindex{stringify}
3146 @xref{Value Stringification Protocol}.
3153 @node Versioning API, , Extension API, API Quick Reference
3154 @section Versioning API
3156 @defun version &optional (TYPE :number)
3157 @xref{Version Numbering}.
3160 @defvr Constant +release-major-level+
3161 @defvrx Constant +release-minor-level+
3162 @defvrx Constant +release-status+
3163 @defvrx Constant +release-status-level+
3164 @defvrx Constant +release-name+
3165 @xref{Version Numbering}.
3170 @c ====================================================================
3172 @c ====================================================================
3173 @node Indexes, Acknowledgments, API Quick Reference, Top
3177 * Concept Index:: Well, the concept index
3178 * Function Index:: Well, the function index
3179 * Variable Index:: Well, the variable index
3180 * Data Type Index:: Well, the data type index
3187 @node Concept Index, Function Index, Indexes, Indexes
3196 @node Function Index, Variable Index, Concept Index, Indexes
3205 @node Variable Index, Data Type Index, Function Index, Indexes
3214 @node Data Type Index, , Variable Index, Indexes
3220 @c ====================================================================
3222 @c ====================================================================
3223 @node Acknowledgments, , Indexes, Top
3224 @appendix Acknowledgments
3225 The following people have contributed bug reports or fixes, suggestions,
3226 compiler support or any other kind of help. You have my gratitude!
3228 @multitable @columnfractions .99
3230 Antony @emph{something}@*
3233 François-René Rideau@*
3243 @c LocalWords: Clon clon cmdline Clonification tty emph CmdLine clonified SGR
3244 @c LocalWords: clonfiscated clonistified clonificated clonificationated samp
3245 @c LocalWords: cindex subsubsection pxref Didier Nuker postfix Runtime cth
3246 @c LocalWords: cartouche toplevel prepended IEC
3248 @c user.texi ends here