Document that CLISP's CFFI dependency is now optional.
[clon.git] / doc / user.texi
blobfaf12b7226cde7a10882c630fcaf6bcb1e663582
1 \input texinfo
3 @c user.texi --- User manual
5 @c Copyright (C) 2010, 2011 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 Clon is free software; you can redistribute it and/or modify
13 @c it under the terms of the GNU General Public License version 3,
14 @c as published by the Free Software Foundation.
16 @c Clon is distributed in the hope that it will be useful,
17 @c but WITHOUT ANY WARRANTY; without even the implied warranty of
18 @c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 @c GNU General Public License for more details.
21 @c You should have received a copy of the GNU General Public License
22 @c along with this program; if not, write to the Free Software
23 @c Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 @c Commentary:
28 @c Contents management by FCM version 0.1.
31 @c ====================================================================
32 @c Header
33 @c ====================================================================
34 @c %**start of header
35 @setfilename clon-user.info
36 @settitle The Clon User Manual
37 @afourpaper
38 @c %**end of header
42 @c ====================================================================
43 @c Settings
44 @c ====================================================================
45 @set VERSION 1.0 beta 18 "Michael Brecker"
46 @set COPYRIGHT_DATE 2010, 2011
47 @setchapternewpage odd
48 @setcontentsaftertitlepage
49 @documentdescription
50 The Clon User Manual for version @value{VERSION}.
51 @end documentdescription
55 @c ====================================================================
56 @c New Commands
57 @c ====================================================================
59 @macro clon
60 @t{Clon}
61 @end macro
63 @macro cl
64 Common Lisp
65 @end macro
67 @macro tty
68 @t{tty}
69 @end macro
71 @macro etc
72 @i{etc.}
73 @end macro
75 @macro eg
76 @i{e.g.}
77 @end macro
79 @macro ie
80 @i{i.e.}
81 @end macro
83 @macro perse
84 @i{per-se}
85 @end macro
87 @macro cmdline
88 command-line
89 @end macro
91 @macro CmdLine
92 Command-Line
93 @end macro
95 @macro bioption{name}
96 @option{--clon-\name\}
97 @end macro
100 @c --------------------------------
101 @c Manuals cross-referencing macros
102 @c --------------------------------
103 @c The following 3 macros are here to circumvent the info filenames
104 @c changes, when referencing the end-user manual:
106 @macro pxenduserref{node}
107 @ifinfo
108 @pxref{\node\, , , clon-enduser, The Clon End-User Manual}
109 @end ifinfo
110 @ifnotinfo
111 @pxref{\node\, , , enduser, The Clon End-User Manual}
112 @end ifnotinfo
113 @end macro
115 @macro xenduserref{node}
116 @ifinfo
117 @xref{\node\, , , clon-enduser, The Clon End-User Manual}
118 @end ifinfo
119 @ifnotinfo
120 @xref{\node\, , , enduser, The Clon End-User Manual}
121 @end ifnotinfo
122 @end macro
124 @macro enduserref{node}
125 @ifinfo
126 @ref{\node\, , , clon-enduser, The Clon End-User Manual}
127 @end ifinfo
128 @ifnotinfo
129 @ref{\node\, , , enduser, The Clon End-User Manual}
130 @end ifnotinfo
131 @end macro
134 @c ---------------
135 @c Indexing macros
136 @c ---------------
138 @c Concept index
139 @c -------------
141 @c Built-in options
142 @macro bioindex{opt}
143 @cindex @t{--clon-\opt\}
144 @cindex Built-In Options, @t{--clon-\opt\}
145 @cindex Options, built-in, @t{--clon-\opt\}
146 @end macro
148 @c Common option properties
149 @macro copindex{prop}
150 @cindex Options, common properties, @t{\prop\}
151 @cindex Common Option Properties, @t{\prop\}
152 @end macro
154 @c Options
155 @c #### NOTE: not an alias because of argument syntax.
156 @macro oindex{name,class}
157 @cindex \name\ (@t{\class\})
158 @cindex Options, \name\ (@t{\class\})
159 @ocindex{\class\}
160 @end macro
162 @c Valued options
163 @macro voindex{name,class}
164 @cindex \name\ (@t{\class\})
165 @cindex Valued Options, \name\ (@t{\class\})
166 @cindex Options, valued, \name\ (@t{\class\})
167 @ocindex{\class\}
168 @end macro
170 @c Common valued option properties
171 @macro cvopindex{prop}
172 @cindex Valued Options, common properties, @t{\prop\}
173 @cindex Common Valued Option Properties, @t{\prop\}
174 @cindex Options, valued, common properties, @t{\prop\}
175 @end macro
177 @c Valued option properties
178 @macro vopindex{name,class,prop}
179 @cindex \name\ (@t{\class\}), properties, @t{\prop\}
180 @cindex Valued Options, \name\ (@t{\class\}), properties, @t{\prop\}
181 @cindex Options, valued, \name\ (@t{\class\}), properties, @t{\prop\}
182 @end macro
184 @c Functions index
185 @c ---------------
187 @c Function options
188 @macro foindex{func,opt}
189 @findex \func\@r{, options, }\opt\
190 @end macro
192 @c Function items
193 @macro fiindex{func,item}
194 @findex \func\@r{, items, }\item\
195 @end macro
197 @c Function keys
198 @macro fkindex{func,key}
199 @findex \func\@r{, keys, }\key\
200 @end macro
202 @c Function initargs
203 @macro fiaindex{func,arg}
204 @findex \func\@r{, initargs, }\arg\
205 @end macro
207 @c Generic functions sub-index
208 @macro gfsubindex{func}
209 @findex @r{Generic Functions, }\func\
210 @end macro
212 @c Generic functions
213 @macro gfindex{func}
214 @findex \func\
215 @gfsubindex{\func\}
216 @end macro
218 @c Generic function methods
219 @macro gfmindex{func,method}
220 @findex \func\@r{, methods, }\method\
221 @findex @r{Generic Functions, }\func\@r{, methods, }\method\
222 @end macro
224 @c #### FIXME: I need this because when using @defun, the function is
225 @c referenced directly but not under the Constructors sub-index. This
226 @c sucks because what I would like is the ability to define my own
227 @c @defXXX macros, which apparently I can't. Besides, doing this
228 @c produces 2 separate index entries, instead of only one with two pagerefs.
229 @c This problem stands for @gfsubindex (see above), @rfsubindex (see
230 @c below) and @ecsubindex (see below) as well.
231 @c Constructor functions sub-index
232 @macro cfsubindex{func}
233 @findex @r{Constructors, }\func\
234 @end macro
236 @c Constructor functions
237 @macro cfindex{func}
238 @findex \func\
239 @cfsubindex{\func\}
240 @end macro
242 @c Constructor function initargs
243 @macro cfiaindex{func,arg}
244 @fiaindex{\func\, \arg\}
245 @findex @r{Constructors, }\func\@r{, initargs, }\arg\
246 @end macro
248 @c Reader functions subindex
249 @macro rfsubindex{func}
250 @findex @r{Readers, }\func\
251 @end macro
253 @c Reader functions
254 @macro rfindex{func}
255 @findex \func\
256 @rfsubindex{\func\}
257 @end macro
260 @c Variables index
261 @c ---------------
263 @c Environment variables
264 @macro evindex{var}
265 @vindex \var\
266 @vindex @r{Environment, }\var\
267 @end macro
269 @c Built-in environment variables
270 @macro bievindex{var}
271 @evindex{CLON_\var\}
272 @end macro
275 @c Data Types index
276 @c ----------------
278 @c Classes
279 @macro clsindex{cls}
280 @tpindex \cls\
281 @tpindex @r{Classes, }\cls\
282 @end macro
284 @c Class slots
285 @macro clssindex{cls,slot}
286 @tpindex \cls\@r{, slots, }\slot\
287 @tpindex @r{Classes, }\cls\@r{, slots, }\slot\
288 @end macro
290 @c Class initargs
291 @macro clsiaindex{cls,arg}
292 @tpindex \cls\@r{, initargs, }\arg\
293 @tpindex @r{Classes, }\cls\@r{, initargs, }\arg\
294 @end macro
296 @c Option classes
297 @macro ocindex{cls}
298 @clsindex{\cls\}
299 @tpindex @r{Option Classes, }\cls\
300 @end macro
302 @c Error conditions subindex
303 @macro ecsubindex{cond}
304 @tpindex @r{Error Conditions, }\cond\
305 @end macro
307 @c Error conditions
308 @macro ecindex{cond}
309 @tpindex \cond\
310 @ecsubindex{\cond\}
311 @end macro
313 @c Error condition slots
314 @macro ecsindex{cond,slot}
315 @tpindex \cond\@r{, slots, }\slot\
316 @tpindex @r{Error Conditions, }\cond\@r{, slots, }\slot\
317 @end macro
319 @c Packages
320 @macro pkgindex{name}
321 @tpindex \name\
322 @tpindex @r{Packages, }\name\
323 @end macro
327 @c ====================================================================
328 @c Info Category and Directory
329 @c ====================================================================
330 @dircategory Common Lisp
331 @direntry
332 * Clon User: (clon-user).               The Clon User Manual.
333 @end direntry
337 @c ====================================================================
338 @c Copying
339 @c ====================================================================
340 @copying
341 @quotation
342 Copyright @copyright{} @value{COPYRIGHT_DATE} Didier Verna.
344 Permission is granted to make and distribute verbatim copies of this
345 manual provided the copyright notice and this permission notice are
346 preserved on all copies.
348 @ignore
349 Permission is granted to process this file through TeX and print the
350 results, provided the printed document carries a copying permission
351 notice identical to this one except for the removal of this paragraph
352 (this paragraph not being relevant to the printed manual).
354 @end ignore
355 Permission is granted to copy and distribute modified versions of this
356 manual under the conditions for verbatim copying, provided also that the
357 sections entitled ``Copying'' and ``GNU General Public License'' are
358 included exactly as in the original, and provided that the entire
359 resulting derived work is distributed under the terms of a permission
360 notice identical to this one.
362 Permission is granted to copy and distribute translations of this manual
363 into another language, under the above conditions for modified versions,
364 except that this permission notice may be stated in a translation
365 approved by the Free Software Foundation.
366 @end quotation
367 @end copying
371 @c ====================================================================
372 @c Title Page
373 @c ====================================================================
374 @titlepage
375 @title The Clon User Manual
376 @subtitle The @CmdLine{} Options Nuker, Version @value{VERSION}
377 @vskip 2cm
378 @image{clon,16cm}
379 @author Didier Verna <@email{didier@@lrde.epita.fr}>
380 @page
381 @vskip 0pt plus 1filll
382 @insertcopying
384 @hfill Cover art by Alexis Angelidis.
385 @end titlepage
389 @c ====================================================================
390 @c Table of Contents
391 @c ====================================================================
392 @contents
396 @c ====================================================================
397 @c Master Menu
398 @c ====================================================================
399 @ifnottex
400 @node Top, Copying, (dir), (dir)
401 @top The Clon User Manual
403 This is the @clon{} User Manual for @clon{} version @value{VERSION}:
404 it explains how to use @clon{} in your application.
406 @menu
407 * Copying::                 The GNU General Public License
408 * Introduction::            What Clon is all about
409 * Quick Start::             For the brave and the impatient
410 * Using Clon::              Clonificating your application
411 * Extending Clon::          Creating your own option types
412 * Advanced Usage::          Things rarely needed
413 * Conclusion::              That's all folks
414 * Portability::             The mine field
415 * API Quick Reference::     The Complete protocols
416 * Indexes::                 Concept, Function and Variable
417 @end menu
419 @insertcopying
420 @end ifnottex
424 @c ====================================================================
425 @c Copying
426 @c ====================================================================
427 @node Copying, Introduction, Top, Top
428 @unnumbered Copying
430 @quotation
431 @clon{} is free software; you can redistribute it and/or modify it under
432 the terms of the GNU General Public License version 3, as published by
433 the Software Foundation.
435 @clon{} is distributed in the hope that it will be useful, but WITHOUT
436 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
437 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
438 more details.
440 You should have received a copy of the GNU General Public License along
441 with this program; if not, write to the Free Software Foundation, Inc.,
442 675 Mass Ave, Cambridge, MA 02139, USA.
443 @end quotation
447 @c ====================================================================
448 @c Introduction
449 @c ====================================================================
450 @node Introduction, Quick Start, Copying, Top
451 @chapter Introduction
453 @clon{} is a library for managing @cmdline{} options in standalone @cl{}
454 applications. It provides a unified option syntax with both short and
455 long names, automatic completion of partial names and automatic
456 retrieval/conversion of option arguments from the @cmdline{}, associated
457 environment variables, fallback or default values. @clon{} comes with a
458 set of extensible option types (switches, paths, strings @etc{}).
459 @clon{} also provides automatic generation and formatting of help
460 strings, with support for highlighting on @tty{}'s through ISO/IEC 6429
461 SGR. This formatting is customizable through @emph{themes}.
463 Depending on the target audience, @clon{} stands for either ``The
464 @CmdLine{} Options Nuker'' or ``The @cl{} Options Nuker''. @clon{} also
465 has a recursive acronym: ``@clon{} Likes Options Nuking'', and a reverse
466 one: ``Never Omit to Link with @clon{}''. Other possible expansions of
467 the acronym are still being investigated.
469 This manual is for the @clon{} @emph{user}, that is, the developer of a
470 @cl{} application who wants to use @clon{} for @cmdline{} option
471 management@footnote{An application using @clon{} for its @cmdline{}
472 option management is said to be @emph{clonified}. It is also possible to
473 say @emph{clonfiscated}. However, we advise against using
474 @emph{clonistified}. The term @emph{clonificated} is also considered bad
475 style, and the use of @emph{clonificationated} is strictly prohibited.}.
476 As opposed to the user of the @emph{library}, the user of an
477 @emph{application} powered by @clon{} is called an @emph{end-user}.
478 @clon{} provides both a user manual (this one) and an end-user manual
479 (@pxenduserref{Top}). Everybody should read the end-user manual first.
481 @ref{Quick Start} provides a very short example in order to give an
482 overview of what's coming next. @ref{Using Clon} explains in detail how
483 to clonify your application, and @ref{Extending Clon} describe how to
484 extend @clon{} with your own option types.
488 @c ====================================================================
489 @c Quick Start
490 @c ====================================================================
491 @node Quick Start, Using Clon, Introduction, Top
492 @chapter Quick Start
493 In this chapter, we assume that you have properly installed @clon{} (see
494 the @file{INSTALL} file in the distribution), and we build a very short
495 program to get you started (let's call it @file{quickstart.lisp}).
497 @menu
498 * Full Source::         The complete source code
499 * Explanation::         Step-by-step code walking
500 @end menu
503 @c -----------
504 @c Full Source
505 @c -----------
506 @node Full Source, Explanation, Quick Start, Quick Start
507 @section Full Source
508 For cut'n paste convenience, the complete source code is given below.
509 For a slightly longer example, have a look at the demonstration program
510 called @file{simple} in the distribution.
512 @cartouche
513 @verbatim
514 (in-package :cl-user)
516 (require :asdf)
517 (asdf:operate 'asdf:load-op :com.dvlsoft.clon)
518 (use-package :com.dvlsoft.clon)
520 (defsynopsis (:postfix "FILES...")
521   (text :contents "A very short program.")
522   (group (:header "Immediate exit options:")
523     (flag :short-name "h" :long-name "help"
524       :description "Print this help and exit.")
525     (flag :short-name "v" :long-name "version"
526           :description "Print version number and exit.")))
528 (defun main ()
529   "Entry point for our standalone application."
530   (make-context)
531   (when (getopt :short-name "h")
532     (help)
533     (exit))
534   (do-cmdline-options (option name value source)
535     (print (list option name value source)))
536   (terpri)
537   (exit))
539 (dump "quickstart" main)
540 @end verbatim
541 @end cartouche
544 @c -----------
545 @c Explanation
546 @c -----------
547 @node Explanation, , Full Source, Quick Start
548 @section Explanation
549 Let's examine this program step-by-step now.
551 @pkgindex{com.dvlsoft.clon}
552 First, we put ourselves in the @cl{} user package, and load @clon{}.
553 @clon{} lives in a package named @samp{com.dvlsoft.clon}.
555 @cartouche
556 @verbatim
557 (in-package :cl-user)
559 (require :asdf)
560 (asdf:operate 'asdf:load-op :com.dvlsoft.clon)
561 (use-package :com.dvlsoft.clon)
562 @end verbatim
563 @end cartouche
565 In fact, using the @clon{} package directly is done here for simplicity,
566 but is not recommended. In case you find the package name too long to
567 prefix every symbol with, @clon{} provides a utility function that
568 allows you to add (and use) a shorter nickname instead (the
569 demonstration programs in the distribution show how to use it):
571 @cindex Package, nicknames
572 @defun nickname-package &optional NICKNAME
573 Add NICKNAME (:CLON by default) to the :COM.DVLSOFT.CLON package.
574 @end defun
576 @cindex Synopsis
577 @findex defsynopsis
578 @cindex Postfix
579 @cindex Text, in synopsis
580 @cindex Options, in synopsis
581 @cindex Groups, in synopsis
582 @cindex Help String
583 The next thing you want to do is to create a set of options, groups or
584 texts that your application will recognize and/or display in its help
585 string. The structure of your @cmdline{} is known to @clon{} as the
586 @dfn{synopsis}. In order to create it, use the macro @code{defsynopsis}.
588 @foindex{defsynopsis,:postfix}
589 @fiindex{defsynopsis,text}
590 @fiindex{defsynopsis,options}
591 @fiindex{defsynopsis,group}
592 @cartouche
593 @verbatim
594 (defsynopsis (:postfix "FILES...")
595   (text :contents "A very short program.")
596   (group (:header "Immediate exit options:")
597     (flag :short-name "h" :long-name "help"
598       :description "Print this help and exit.")
599     (flag :short-name "v" :long-name "version"
600           :description "Print version number and exit.")))
601 @end verbatim
602 @end cartouche
604 Note that the synopsis has a double role: it not only serves to define
605 the options recognized by your application, but also the order in which
606 every element appears in the help string. In that particular example, we
607 define a line of text and a group with a header and two flags.
609 @cindex Context
610 @cfindex{make-context}
611 Now, we are going to define a function @code{main} for our standalone
612 application. The first thing that we need to do is create a
613 @dfn{context}. A context is an object that @clon{} uses to store various
614 things, including some state related to the parsing of the @cmdline{}.
615 You create a context with the function @code{make-context}.
617 @cartouche
618 @verbatim
619 (defun main ()
620   "Entry point for our standalone application."
621   (make-context)
622 @end verbatim
623 @end cartouche
625 @cindex Options Retrieval, explicit
626 @cindex Retrieval, of options, explicit
627 @findex getopt
628 @cindex Help String, display
629 @findex help
630 At that point, @clon{} is ready to retrieve the options you want from
631 the @cmdline{}. Let's first see if the user has called the option
632 @option{-h}, and give him the help string. Option retrieval is done with
633 the function @code{getopt}, and automatic help string output with the
634 function @code{help}. Note that what we do here is @emph{not} process
635 the @cmdline{} in sequence, but look directly for a specific option by
636 name (this retrieval method is said to be @dfn{explicit}).
638 @fkindex{getopt,:short-name}
639 @cartouche
640 @verbatim
641   (when (getopt :short-name "h")
642     (help)
643     (exit))
644 @end verbatim
645 @end cartouche
647 @findex exit
648 The @code{exit} function is a wrapper around an
649 implementation-dependent way to exit (shall I say quit?) the @cl{}
650 environment, hence the program. It takes an optional argument that
651 stands for the exit status.
653 @cindex Options Retrieval, sequential
654 @cindex Retrieval, of options, sequential
655 @findex do-cmdline-options
656 And now, we are going to retrieve the other options and simply print
657 them. This time however, we process the @cmdline{} sequentially (so this
658 retrieval method is said to be @dfn{sequential}). This is done with the
659 @code{do-cmdline-options} macro. We also close the @code{main} function.
661 @cartouche
662 @verbatim
663   (do-cmdline-options (option name value source)
664     (print (list option name value source)))
665   (terpri)
666   (exit))
667 @end verbatim
668 @end cartouche
670 Finally, time to save the Lisp image.
672 @findex dump
673 @cartouche
674 @verbatim
675 (dump "quickstart" main)
676 @end verbatim
677 @end cartouche
679 The first argument to @code{dump} is the name of the executable to
680 produce, and the second argument is the name of the function to call
681 automatically at startup.
683 In order to get a standalone executable from this program, all you need
684 to do now is to type @samp{CC=gcc sbcl --script quickstart.lisp}. Note
685 that the actual way of dumping executables is compiler-dependent. For
686 more information on the proper way to do it and on the compilers
687 currently supported, see @ref{Portability}.
691 @c ====================================================================
692 @c Using Clon
693 @c ====================================================================
694 @node Using Clon, Extending Clon, Quick Start, Top
695 @chapter Using Clon
697 Using @clon{} in your application is a two stages process. In phase 1,
698 you create a @dfn{synopsis}, which is a description of your
699 application's @cmdline{} and a @dfn{context}, which describes this
700 specific execution of the program. In phase 2, you retrieve the option
701 values and possibly display help strings. Phase 1 is called the
702 @dfn{initialization phase}, while phase 2 is called the @dfn{runtime
703 phase}.
705 @menu
706 * Synopsis Definition:: Describing your command-line
707 * Context Creation::    Instantiating your command-line
708 * Integrity Checks::    Verifying the Clon semantics
709 * Option Retrieval::    Getting the options values
710 * Help::                Generating the help string
711 @end menu
714 @c -------------------
715 @c Synopsis Definition
716 @c -------------------
717 @node Synopsis Definition, Context Creation, Using Clon, Using Clon
718 @section Synopsis Definition
720 @cindex Initialization Phase
721 @cindex Phase, initialization
722 @cindex Synopsis
723 @cindex Help String
724 Step one of the @clon{} initialization phase consists in defining a
725 @dfn{synopsis}. A synopsis is essentially a description of your
726 application's @cmdline{}: it describes what are the available options,
727 whether your application has a postfix @etc{} The synopsis, however,
728 plays a second role: it also describes the contents of your
729 application's help string. When you create a synopsis, you describe the
730 @cmdline{} and the help string at the same time.
732 @menu
733 * Synopsis Items::              Defsynopsis and its contents
734 * Built-In Option Types::       The exhaustive list
735 * Advanced Synopsis Creation::  The non-declarative way
736 @end menu
738 @node Synopsis Items, Built-In Option Types, Synopsis Definition, Synopsis Definition
739 @subsection Synopsis Items
740 Look again at the synopsis definition provided in @ref{Quick Start}.
742 @cartouche
743 @verbatim
744 (defsynopsis (:postfix "FILES...")
745   (text :contents "A very short program.")
746   (group (:header "Immediate exit options:")
747     (flag :short-name "h" :long-name "help"
748           :description "Print this help and exit.")
749     (flag :short-name "v" :long-name "version"
750           :description "Print version number and exit.")))
751 @end verbatim
752 @end cartouche
754 You define a synopsis with the @code{defsynopsis} macro.
756 @defmac defsynopsis ([OPTIONS@dots{}]) ITEMS@dots{}
757 Define a new synopsis and return it. @var{OPTIONS} are key/value pairs.
758 @var{ITEMS} are text, group or option descriptions.
760 The following @var{OPTIONS} are currently available.
761 @table @t
762 @item :postfix
763 @cindex Postfix
764 @foindex{defsynopsis,:postfix}@c
765 @cindex Command-Line, remainder
766 @cindex Remainder, of command-line
767 A string which will appear at the end of the synopsis line in the help
768 string. When you provide a postfix, you also implicitely tell @clon{}
769 that your application accepts non-option arguments at the end of the
770 @cmdline{} (this is called the @dfn{remainder} of the @cmdline{}). See
771 @enduserref{Option Separator} for more information on the behavior of
772 @clon{} with respect to postfixes. Also, see @ref{Command-Line
773 Remainder} on how to access the @cmdline{} remainder.
774 @end table
775 @end defmac
777 We now examine the syntax for each possible @var{ITEM}.
778 @menu
779 * Text::        Adding arbitrary text
780 * Options::     Adding options
781 * Groups::      Adding groups
782 @end menu
784 @node Text, Options, Synopsis Items, Synopsis Items
785 @subsubsection Text
786 @cindex Text
787 @cindex Text, in synopsis
788 @fiindex{defsynopsis,text}
789 In order to add arbitrary text to your help string, use the following
790 form:
792 @noindent
793 @t{(text} [@var{OPTIONS@dots{}}]@t{)}
795 @var{OPTIONS} are key/value pairs. The following @var{OPTIONS} are
796 currently available.
797 @table @t
798 @item :contents
799 @cindex Text, contents
800 The actual text string. Try to make proper sentences when adding
801 arbitrary text. You can use explicit newline characters in your text if
802 you really want to go next line, but in general, you should not worry
803 about the formatting because the themes are here to do so. In
804 particular, don't finish your text with a newline. This would break
805 potential theme specifications.
806 @item :hidden
807 @cindex Hidden Text
808 @cindex Text, hidden
809 @cindex Help String
810 When non-@code{nil}, the text won't appear in the help string. Hidden
811 texts can still be displayed individually though (@pxref{Help}).
812 @end table
814 @node Options, Groups, Text, Synopsis Items
815 @subsubsection Options
816 @cindex Options
817 @cindex Options, in synopsis
818 @fiindex{defsynopsis,options}
819 In order to add an option to your help string, you must provide a list
820 beginning with the option type and followed by key/value pairs
821 describing the option's properties. For instance, to add a flag with a
822 short name and a description, you could do this:
824 @verbatim
825 (flag :short-name "h" :description "Print this help and exit.")
826 @end verbatim
828 Option properties vary depending on the option type. The exact list of
829 available option types, and the corresponding properties are described
830 in @ref{Built-In Option Types}.
832 @node Groups, , Options, Synopsis Items
833 @subsubsection Groups
834 @cindex Groups
835 @cindex Groups, in synopsis
836 @fiindex{defsynopsis,group}
837 In order to add a group to your help string, use the following form:
839 @noindent
840 @t{(group} ([@var{OPTIONS@dots{}}]) @var{ITEMS@dots{}}@t{)}
842 @cindex Text, in groups
843 @cindex Options, in groups
844 @cindex Groups, in groups
845 @var{OPTIONS} are key/value pairs. @var{ITEMS} simply are arbitrary
846 text, option or sub-group descriptions as we've just seen.
848 The following @var{OPTIONS} are currently available.
849 @table @t
850 @item :header
851 @cindex Group Header
852 @cindex Header, in group
853 @foindex{defgroup,:header}@c
854 A string which will be displayed above the group's contents in the help
855 string. The same formatting recommendations as for arbitrary text apply
856 (@pxref{Text}).
857 @item :hidden
858 @cindex Hidden Groups
859 @cindex Groups, hidden
860 @foindex{defgroup,:hidden}@c
861 @cindex Help String
862 @cindex Built-In Groups
863 @cindex Groups, built-in
864 @bioindex{help}
865 When non-@code{nil}, the group won't appear in the help string. Hidden
866 groups can still be displayed individually though (@pxref{Help}). For
867 instance, the @clon{} built-in group is hidden in the regular help
868 string, but the @bioption{help} option still displays it individually.
869 @end table
871 @node Built-In Option Types, Advanced Synopsis Creation, Synopsis Items, Synopsis Definition
872 @subsection Built-In Option Types
873 @cindex Built-In Option Types
874 @cindex Options, built-in types
875 @cindex Option Types, built-in
876 In this section, we will review all the built-in option types that
877 @clon{} provides, along with their corresponding properties. You can use
878 them directly in your synopsis description. For adding personal option
879 types to @clon{}, see @ref{New Option Types}.
881 @menu
882 * Common Properties::                   For all options
883 * Flags::                               Built-in options without arguments
884 * Common Valued Option Properties::     For all valued options
885 * Built-In Valued Options::             Built-in options with arguments
886 @end menu
888 @node Common Properties, Flags, Built-In Option Types, Built-In Option Types
889 @subsubsection Common Properties
890 @cindex Options, common properties
891 @cindex Common Option Properties
892 @clsindex{option}
893 All option types in @clon{}, including those you define yourself
894 (@pxref{New Option Types}), have a set of basic, common properties. Here
895 is a list of them.
897 @table @code
898 @item :short-name
899 @copindex{:short-name}
900 The option's short name. A string or @code{nil}.
901 @item :long-name
902 @copindex{:long-name}
903 The option's long name. A string or @code{nil}.
904 @item :description
905 @copindex{:description}
906 The option's descriptive text. A string or @code{nil}. The same
907 formatting recommendations as for arbitrary text apply (@pxref{Text}).
908 @item :env-var
909 @copindex{:env-var}
910 The option's associated environment variable. A string or @code{nil}.
911 @item :hidden
912 @copindex{:hidden}
913 @cindex Hidden Options
914 @cindex Options, hidden
915 @cindex Help String
916 When non-@code{nil}, the option won't appear in the help string. Hidden
917 options can still be displayed individually though (@pxref{Help}).
918 @end table
920 Note that an option is required to have at least one name (either short
921 or long). Non-@code{nil} but empty names are also prohibited, and of
922 course, a short name cannot begin with a dash (otherwise, it would be
923 mistaken for a long name, but did I really need to mention this?).
925 @node Flags, Common Valued Option Properties, Common Properties, Built-In Option Types
926 @subsubsection Flags
927 @oindex{Flags,flag}
928 In @clon{}, options that don't take any argument are of type
929 @code{flag}. These options don't provide additional properties on top of
930 the common set described in @ref{Common Properties}. All properties
931 default to @code{nil}.
933 @node Common Valued Option Properties, Built-In Valued Options, Flags, Built-In Option Types
934 @subsubsection Common Valued Option Properties
935 @cindex Valued Options
936 @cindex Options, valued
937 @clsindex{valued-option}
938 All non-flag options in @clon{} are said to be @dfn{valued}. All valued
939 options, including those you define yourself (@pxref{New Option Types}),
940 share a set of additional properties. Here is a list of them.
942 @cindex Valued Options, common properties
943 @cindex Common Valued Option Properties
944 @cindex Options, valued, common properties
945 @table @code
946 @item :argument-name
947 @cvopindex{:argument-name}
948 The name of the option's argument, as it appears in the help string. It
949 defaults to @code{"ARG"}, so that for instance, a @samp{name} option
950 would appear like this: @samp{--name=ARG}.
951 @item :argument-type
952 @cvopindex{:argument-type}
953 The status of the argument. Possible values are @code{:required} (the
954 default) and @code{:mandatory} which are synonyms, or @code{:optional}.
955 @item :fallback-value
956 @cvopindex{:fallback-value}
957 @cindex Values, source, fallback
958 @item :default-value
959 @cvopindex{:default-value}
960 @cindex Values, source, default
961 The option's fallback and default values. Remember that a fallback value
962 only makes sense when the argument is optional. Besides, also when the
963 argument is optional, you need to provide at least a fallback or a
964 default value (or both of course; see @enduserref{Value Sources}).
965 @end table
967 @node Built-In Valued Options, , Common Valued Option Properties, Built-In Option Types
968 @subsubsection Built-In Valued Options
969 @cindex Option Types, valued
970 @cindex Built-In Option Types, valued
971 @cindex Options, built-in types, valued
972 @cindex Option Types, built-in, valued
973 @clon{} currently defines 6 built-in valued option types. These option
974 types may change the default value for some common properties, and / or
975 provide additional properties of their own. All of this is described
976 below.
978 @table @code
979 @item stropt
980 @voindex{Strings,stropt}@c
981 @cvopindex{:argument-name}@c
982 This option type is for options taking strings as their argument. String
983 options don't provide any additional properties, but their default
984 argument name is changed from @code{"ARG"} to @code{"STR"}.
985 @item lispobj
986 @voindex{Lisp Objects,lispobj}@c
987 @cvopindex{:argument-name}@c
988 @vopindex{Lisp Objects,lispobj,:typespec}@c
989 @bioindex{line-width}@c
990 This option type is for options taking any kind of Lisp object as their
991 argument. @code{lispobj} options change their default argument name from
992 @code{"ARG"} to @code{"OBJ"}. Also, they provide an additional property
993 called @code{:typespec} which must be a @cl{} type specifier that the
994 argument must satisfy. It defaults to @code{t}. Look at the
995 @bioption{line-width} built-in option for an example.
996 @item enum
997 @voindex{Enumerations,enum}@c
998 @cvopindex{:argument-name}@c
999 @vopindex{Enumerations,enum,:enum}@c
1000 @bioindex{version}@c
1001 This option type is for options taking values from an enumerated set of
1002 keywords. @code{enum} options change their default argument name from
1003 @code{"ARG"} to @code{"TYPE"}. Also, they provide an additional property
1004 called @code{:enum} to store the list of @cl{} keywords enumerating the
1005 possible values. The end-user does not use a colon when providing an
1006 argument to an @code{enum} option. Only the keyword's name. The end-user
1007 also has the ability to abbreviate the possible values. An empty
1008 argument is considered as an abbreviation for the first element in the
1009 set. Look at the @bioption{version} built-in option for an example.
1010 @item path
1011 @bioindex{search-path}@c
1012 @bioindex{theme}@c
1013 @voindex{Paths,path}@c
1014 @cvopindex{:argument-name}@c
1015 @vopindex{Paths,path,:type}@c
1016 This option type is for options taking a colon-separated list of
1017 pathnames as argument. @code{path} options change their default argument
1018 name from @code{"ARG"} to @code{"PATH"}. Also, they provide an
1019 additional property called @code{:type} which specifies the kind of path
1020 which is expected. Possible values are: @code{:file}, @code{:directory},
1021 @code{:file-list}, @code{:directory-list} or @code{nil} (meaning that
1022 anything is allowed). Null paths are allowed, and may be provided by an
1023 empty argument. Look at the @bioption{search-path} and
1024 @bioption{theme} built-in options for examples.
1025 @item switch
1026 @voindex{Switches,switch}@c
1027 @cvopindex{:argument-name}@c
1028 @cvopindex{:argument-type}@c
1029 @vopindex{Switches,switch,:argument-style}@c
1030 This option type is for Boolean options. @code{switch} options change
1031 their default argument type from required to optional and provide a
1032 fallback value of @code{t} automatically for optional arguments.
1033 @code{switch} options provide a new property called
1034 @code{:argument-style}. Possible values are @code{:yes/no} (the
1035 default), @code{:on/off}, @code{:true/false}, @code{:yup/nope},
1036 @code{:yeah/nah}. This property affects the way the argument name and
1037 true or false values are advertized in help strings. However, all
1038 possible arguments forms (@pxenduserref{Switches}) are always available
1039 to all switches.
1040 @item xswitch
1041 @voindex{Extended Switches,xswitch}@c
1042 @cvopindex{:argument-name}@c
1043 @cvopindex{:argument-type}@c
1044 @vopindex{Extended Switches,xswitch,:argument-style}@c
1045 @vopindex{Extended Switches,xswitch,:enum}@c
1046 @bioindex{highlight}@c
1047 This option type stands for @dfn{extended} switch. Extended switches
1048 result from the mating of a male switch and a female enumeration, or the
1049 other way around (elementary decency prevents me from describing this
1050 mating process in detail): their possible values are either Boolean or
1051 from an @code{:enum} property as in the case of @code{enum} options. As
1052 simple switches, @code{xswitch} options change their default argument
1053 type from required to optional and provide a fallback value of @code{t}
1054 automatically for optional arguments. They also provide the
1055 @code{:argument-style} property. Contrary to switches, however, this
1056 property does not affect the argument name. It only affects the way true
1057 or false values are displayed in help strings. Look at the
1058 @bioption{highlight} built-in option for an example.
1059 @end table
1061 @node Advanced Synopsis Creation, , Built-In Option Types, Synopsis Definition
1062 @subsection Advanced Synopsis Creation
1063 @findex defsynopsis
1064 The fact that @code{defsynopsis} lets you define things in a
1065 @emph{declarative} way has not escaped you. Declarative is nice but
1066 sometimes it gets in the way, so it is time to see how things work under
1067 the hood. Every item in a synopsis is in fact implemented as an object
1068 (an instance of some class), so it turns out that @code{defsynopsis}
1069 simply is a convenience wrapper around the corresponding constructor
1070 functions for all such objects. Instead of using @code{defsynopsis}, you
1071 can then use those constructor functions explicitely.
1073 @menu
1074 * Constructors::        The expansion of defsynopsis
1075 * Advantages::          Yes, but why?
1076 * Group Definition::    The declarative way
1077 @end menu
1079 @node Constructors, Advantages, Advanced Synopsis Creation, Advanced Synopsis Creation
1080 @subsubsection Constructors
1081 Let's have a look at the expansion of @code{defsynopsis} from the quick
1082 start example (@pxref{Quick Start}).
1084 The original code is like this:
1086 @cartouche
1087 @verbatim
1088 (defsynopsis (:postfix "FILES...")
1089   (text :contents "A very short program.")
1090   (group (:header "Immediate exit options:")
1091     (flag :short-name "h" :long-name "help"
1092           :description "Print this help and exit.")
1093     (flag :short-name "v" :long-name "version"
1094           :description "Print version number and exit.")))
1095 @end verbatim
1096 @end cartouche
1098 And once the macro is expanded, it will look like this:
1100 @cfindex make-synopsis
1101 @cfindex make-text
1102 @cfindex make-group
1103 @cfindex make-flag
1104 @findex defsynopsis@r{, expansion}
1105 @cartouche
1106 @verbatim
1107 (make-synopsis :postfix "FILES..."
1108   :item (make-text :contents "A very short program.")
1109   :item (make-group :header "Immediate exit options:"
1110           :item (make-flag :short-name "h"
1111                            :long-name "help"
1112                            :description "Print this help and exit.")
1113           :item (make-flag :short-name "v"
1114                            :long-name "version"
1115                            :description "Print version number and exit.")))
1116 @end verbatim
1117 @end cartouche
1119 As you can see, every synopsis element has a corresponding
1120 @code{make-@var{SOMETHING}} constructor, and the keywords used here and
1121 there in @code{defsyopsis} are in fact initargs to those constructors.
1122 We now examine those constructors in greater detail.
1124 @cindex Options, creation
1125 @defun make-text [@code{:hidden} BOOL] @code{:contents} STRING
1126 @cfsubindex{make-text}
1127 @cfiaindex{make-text,:contents}
1128 @cfiaindex{make-text,:hidden}
1129 Create an arbitrary text object, possibly hidden, whose contents is
1130 @var{STRING}.
1131 @end defun
1133 @c #### FIXME: I would like an environment without indexing here.
1134 @defun make-@var{OPTION} :INITARG INITVAL@dots{}
1135 @cfsubindex{make-@var{OPTION}}
1136 @cfindex make-flag
1137 @cfindex make-stropt
1138 @cfindex make-lispobj
1139 @cfindex make-enum
1140 @cfindex make-path
1141 @cfindex make-switch
1142 @cfindex make-xswitch
1143 Create a new @var{OPTION} object, @var{OPTION} being any built-in option
1144 type (@code{flag}, @code{stropt} @etc{}, see @ref{Built-In Valued
1145 Options}) or user-defined one (@pxref{New Option Types}). For a list of
1146 available initialization arguments (depending on the option type), see
1147 @ref{Built-In Option Types}.
1148 @end defun
1150 @defun make-group [@code{:header} STRING @code{:hidden} BOOL] @
1151 @code{:item} ITEM1 @code{:item} ITEM2@dots{}
1152 @cfsubindex{make-group}
1153 @cfiaindex{make-group,:header}
1154 @cfiaindex{make-group,:hidden}
1155 @cfiaindex{make-group,:item}
1156 @cindex Help String
1157 Create a group object, possibly hidden, whose header is @var{STRING}.
1158 Every @var{ITEM} is an arbitrary text object, option object or group
1159 object. The order is important as it determines the display of the help
1160 string.
1161 @end defun
1163 @defun make-synopsis [@code{:postfix} STRING] @
1164 @code{:item} ITEM1 @code{:item} ITEM2@dots{}
1165 @cfsubindex{make-synopsis}
1166 @cfiaindex{make-synopsis,:postfix}
1167 @cfiaindex{make-synopsis,:item}
1168 @cindex Help String
1169 Create a synopsis object whose postfix is @var{STRING}. Every @var{ITEM} is
1170 an arbitrary text object, option object or group object. The order is
1171 important as it determines the display of the help string.
1172 @end defun
1174 In fact, the @code{defsynopsis} macro allows you to freely mix
1175 declarative forms, constructor calls or whatever Lisp code you may want
1176 to use. The way this works is as follows: if a synopsis @var{ITEM}
1177 (@pxref{Synopsis Items}) is a list whose @code{car} is @code{text},
1178 @code{group}, or any option type (inluding those you define yourselves;
1179 see @ref{New Option Types}), then the @var{ITEM} is expanded as
1180 explained earlier. Otherwise, it is just left @emph{as-is}.
1182 To sum up, here's a example of things you can do in @code{defsynopsis}.
1184 @cartouche
1185 @verbatim
1186 (com.dvlsoft.clon:defsynopsis ()
1187   (flag #| ... |#)
1188   *my-great-option*
1189   (setq *another-option* (com.dvlsoft.clon:make-switch #| ... |#)))
1190 @end verbatim
1191 @end cartouche
1194 @node Advantages, Group Definition, Constructors, Advanced Synopsis Creation
1195 @subsubsection Advantages
1196 @findex defsynopsis
1197 So, why would you want to use constructors directly or mix declarative
1198 and imperative forms in @code{defsynopsis}? There are several reasons
1199 for doing so.
1200 @enumerate
1201 @item
1202 Some people prefer to declare (or should I say, create) their arbitrary
1203 texts, options and groups locally, in files, modules or ASDF components
1204 where they belong. In such a case, you need to keep references to the
1205 corresponding objects in order to compute the synopsis in the end.
1206 @item
1207 Since using constructors explicitely allows you to keep references to
1208 the created objects, these objects can be @emph{reused}. For instance,
1209 you can use the same text at different places, you can also use a single
1210 option several times, or even a single group several times so that its
1211 items appear in different places @etc{} Note that @clon{} knows its way
1212 around multiple occurrences of the same object: even if you use the same
1213 option object several times in a synopsis, @clon{} only maintains a
1214 single option definition.
1215 @end enumerate
1217 @node Group Definition, , Advantages, Advanced Synopsis Creation
1218 @subsubsection Group Definition
1219 There is one last point we need to address in order to complete this
1220 section. There might be times when you need to manipulate an explicit
1221 group object, but the object itself can still be created in a
1222 declarative (or mixed) way because you don't need to keep references on
1223 its items. For this, @clon{} provides a macro called @code{defgroup}.
1225 @defmac defgroup (OPTIONS@dots{}) ITEMS@dots{}
1226 @cindex Groups, in synopsis
1227 @fiindex{defsynopsis,group}
1228 @foindex{defgroup,:header}
1229 @foindex{defgroup,:hidden}
1230 Define a new group and return it. This macro behaves exactly like the
1231 @code{group} form in a call to @code{defsynopsis} (@pxref{Groups}). In
1232 fact, an intermediate step in the expansion of the @code{defsynopsis}
1233 macro is to transform @code{group} forms into @code{defgroup} macro
1234 calls. As for @code{defsynopsis}, @code{defgroup} allows you to mix
1235 declarative forms, constructor calls or any kind of Lisp code.
1236 @end defmac
1240 @c ----------------
1241 @c Context Creation
1242 @c ----------------
1243 @node Context Creation, Integrity Checks, Synopsis Definition, Using Clon
1244 @section Context Creation
1246 @cindex Initialization Phase
1247 @cindex Phase, initialization
1248 @cindex Context
1249 Step two of the @clon{} initialization phase consists in creating a
1250 @dfn{context}. A context is an object representing a particular instance
1251 of your program, for example (and most notably) with an actual
1252 @cmdline{} as the user typed it.
1254 @menu
1255 * Making A Context::            The Constructor function
1256 * Contextual Information::      Interesting context slots
1257 @end menu
1259 @node Making A Context, Contextual Information, Context Creation, Context Creation
1260 @subsection Making A Context
1262 @cfindex{make-context}
1263 You create a context with the @code{make-context} function.
1265 @defun make-context
1266 @cfsubindex{make-context}
1267 Create a new context. That's it.
1268 @end defun
1270 @node Contextual Information, , Making A Context, Context Creation
1271 @subsection Contextual Information
1273 Once a context object is created, you have access to some interesting
1274 contextual information.
1276 @menu
1277 * Program Name::                As it appear on the command-line
1278 * Command-Line Remainder::      The non-options part
1279 @end menu
1281 @node Program Name, Command-Line Remainder, Contextual Information, Contextual Information
1282 @subsubsection Program Name
1283 The application's program name, as it appears on the @cmdline{}, may be
1284 accessed from @clon{}. You may find it easier to do this way, as @clon{}
1285 wraps around implementation-dependent access methods to @code{argv[0]}.
1287 @findex progname
1288 In order to retrieve @code{argv[0]}, use the @code{progname} function
1289 like this: @code{(progname)}.
1291 @node Command-Line Remainder, , Program Name, Contextual Information
1292 @subsubsection Command-Line Remainder
1293 @cindex Remainder, of command-line
1294 @cindex Command-Line, remainder
1295 In the case your @cmdline{} has a remainder (that is, a non-options
1296 part; see @enduserref{Option Separator} and @ref{Synopsis Items}), you
1297 may need to access it in order to process it independently from @clon{}.
1298 Since @clon{} is responsible for parsing the @cmdline{}, it is also in
1299 charge of figuring out where the remainder of the @cmdline{} begins.
1301 @findex remainder
1302 The @cmdline{} remainder is known to @clon{} as soon as a context is
1303 created. You can retrieve it by using the @code{remainder} function like
1304 this: @code{(remainder)}. The remainder is provided as a list of strings.
1308 @c ----------------
1309 @c Integrity Checks
1310 @c ----------------
1311 @node Integrity Checks, Option Retrieval, Context Creation, Using Clon
1312 @section Integrity Checks
1313 @findex defsynopsis
1314 @cfindex{make-context}
1315 At this point, you know about the two necessary steps to initialize
1316 @clon{}: defining a synopsis and creating a context. If you paid
1317 attention to the quick start application (@pxref{Quick Start}), you may
1318 have noticed that @code{defsynopsis} was called as a top-level form
1319 whereas @code{make-context} was called from the function @code{main}. So
1320 why the difference?
1322 First, I hope that you see why a context cannot be created as a toplevel
1323 form. If you do that, you will end-up creating a context relevant to the
1324 Lisp environment from which the application is created, not run.
1326 The synopsis, on the other hand, could be defined either as a toplevel
1327 form, as done in the quick start and the demo programs, or in the
1328 function @code{main}, just before making a context. There is a very good
1329 reason to prefer a toplevel form however: that reason is called
1330 ``integrity checks''.
1332 When you define a synopsis (or any synopsis item, for that matter),
1333 @clon{} performs a number of checks to make sure that you're making a
1334 sensible use of the library. In fact, the number of semantic mistakes
1335 that you can make is quite puzzling. You could for instance define
1336 several options with identical names, forget to provide a fallback or
1337 default value when it is required, provide invalid fallback or default
1338 values, and the list goes on and on. These are just a few examples but
1339 there are many more, and @clon{} checks all of those (I think).
1341 Since those mistakes relate to the definition of the application itself,
1342 they do not depend on a particular execution of it. Consequently, the
1343 sooner @clon{} catches them, the better. If you define your
1344 application's synopsis as a toplevel form, @clon{} will be able to
1345 perform its integrity checks when the application is created, not only
1346 when it is used. In other words, you won't be able to get a working
1347 application until your use of @clon{} is semantically correct.
1349 This is why it is strongly recommended to create synopsis from toplevel
1350 forms, and this also explains why @clon{} chooses @emph{not} to provide
1351 an @code{initialize} function that would wrap around @code{defsynopsis}
1352 and @code{make-context} together.
1356 @c ----------------
1357 @c Option Retrieval
1358 @c ----------------
1359 @node Option Retrieval, Help, Integrity Checks, Using Clon
1360 @section Option Retrieval
1361 @cindex Runtime Phase
1362 @cindex Phase, runtime
1363 @cindex Retrieval, of options
1364 @cindex Options Retrieval
1366 During the runtime phase of @clon{}, your main activity will be to
1367 retrieve options and their values. @clon{} provides two techniques for
1368 retrieving options: you can request the value for a specific option
1369 directly, or you can process the @cmdline{} sequentially, which is the
1370 more traditional approach.
1372 @cindex Command-Line
1373 @findex cmdline
1374 Both of these techniques can be freely combined together at any time,
1375 because @clon{} keeps track of the current status of the @cmdline{}. In
1376 fact, @clon{} never works on the original @cmdline{}, but uses a mutable
1377 @emph{copy} of it after parsing. If you want to access the real
1378 @cmdline{} of your application, you may use the @code{cmdline} function,
1379 which is a wrapper around an implementation-dependent way to access it.
1382 Finally, remember that the @cmdline{} is scanned from left to right
1383 during option retrieval (@pxenduserref{Option Retrieval}).
1385 @menu
1386 * Explicit Retrieval::          Accessing options by name
1387 * Sequential Retrieval::        Accessing options in order
1388 @end menu
1390 @node Explicit Retrieval, Sequential Retrieval, Option Retrieval, Option Retrieval
1391 @subsection Explicit Retrieval
1392 @cindex Options Retrieval, explicit
1393 @cindex Retrieval, of options, explicit
1394 Since @clon{} lets you retrieve options on demand (at any time), it
1395 makes sense to be able to request the value of a specific option
1396 explicitely. For instance, you might want to try the @samp{--help}
1397 option first, without looking at the rest of the @cmdline{} because the
1398 application will in fact quit immediately after having displayed the
1399 help string.
1401 @defun getopt :KEY VALUE@dots{}
1402 Retrieve the value of a specific option. The following @var{:KEY}s are
1403 currently available.
1405 @table @code
1406 @item :short-name
1407 @item :long-name
1408 @fkindex{getopt,:short-name}
1409 @fkindex{getopt,:long-name}
1410 Use one of these 2 keys to specify the name of the option you wish to
1411 retrieve.
1412 @item :option
1413 @fkindex{getopt,:option}
1414 Alternatively, you can use a reference to an option object
1415 (@pxref{Constructors}).
1416 @end table
1418 This function return two values: the option's value and the value's
1419 source (@pxenduserref{Value Sources}).
1420 @end defun
1422 The value's source may have the following forms:
1423 @table @code
1424 @item (:cmdline @var{NAME})
1425 @cindex Values, source, @cmdline{}
1426 This is for options found on the @cmdline{}. @var{NAME} is the name used
1427 on the @cmdline{}. It can be the option's long or short name, or a
1428 completed long name if the option's name was abbreviated. A completed
1429 name displays the omitted parts in parentheses (@code{"he(lp)"} for
1430 instance).
1431 @item (:fallback @var{NAME})
1432 @cvopindex{:fallback-value}
1433 @cindex Values, source, fallback
1434 The same but when the fallback value is used, that is, when an option is
1435 not provided with its (optional) argument.
1436 @item (:default @var{NAME})
1437 @cvopindex{:default-value}
1438 @cindex Values, source, default
1439 The same, but when the default value is used (because there is no
1440 fallback).
1441 @item (:environment @var{VAR})
1442 @copindex{:env-var}
1443 @cindex Values, source, environment
1444 This is for options not found on the @cmdline{} but for which there is
1445 an associated environment variable set in the application's environment.
1446 @var{VAR} is the name of the corresponding environment variable.
1447 @item :default
1448 @cvopindex{:default-value}
1449 @cindex Values, source, default
1450 This is for options not found anywhere, but for which a default value
1451 was provided.
1452 @end table
1454 @oindex{Flags,flag}
1455 @findex getopt
1456 Note that because flags don't take any argument, @code{getopt} returns a
1457 virtual value of @code{t} when they are found or a corresponding
1458 environment variable exists in the environment. For the same reason, a
1459 flag's value source may ony be @code{(:cmdline @var{NAME})} or
1460 @code{(:environment @var{VAR})}.
1462 @findex getopt
1463 When an option is not found anywhere and there is no default value,
1464 @code{getopt} just returns nil (no second value). Also, note that when
1465 your option accepts @code{nil} as a value, you @emph{need} to handle the
1466 second retrun value to make the difference between an option not found,
1467 and an actual value of @code{nil}.
1470 @node Sequential Retrieval, , Explicit Retrieval, Option Retrieval
1471 @subsection Sequential Retrieval
1472 @cindex Options Retrieval, sequential
1473 @cindex Retrieval, of options, sequential
1474 The more traditional approach to option retrieval is to scan the
1475 @cmdline{} for options in their order of appearance. @clon{} supports
1476 this by providing you with one function and two macros, as explained
1477 below.
1479 @defun getopt-cmdline
1480 Get the @dfn{next} @cmdline{} option, that is, the first option on the
1481 @cmdline{} that has not been previously retrieved, either explicitely or
1482 sequentially.
1484 When there are no more options on the @cmdline{}, this function returns
1485 @code{nil}. Otherwise, four values are returned: the corresponding
1486 option object from the synopsis definition (@pxref{Constructors}), the
1487 name used on the @cmdline{}, the option's value and the value source
1488 (@code{:cmdline}, @code{:fallback} or @code{:default}). As in the case
1489 of explicit retrieval (@pxref{Explicit Retrieval}), the option's name
1490 may be completed in case of abbreviation.
1492 @rfindex{short-name}
1493 @rfindex{long-name}
1494 @copindex{:short-name}
1495 @copindex{:long-name}
1496 Unless you keep references to all your option objects (and thus can
1497 compare them directly to the one returned by this function), you can
1498 still identify the retrieved option by using the @code{short-name} and
1499 @code{long-name} readers on it: simply use @code{(long-name
1500 @var{OPTION})} or @code{(short-name @var{OPTION})} and you will get the
1501 corresponding strings.
1502 @end defun
1504 @defmac multiple-value-getopt-cmdline (OPTION NAME VALUE SOURCE) BODY
1505 Evaluate @var{BODY} with @var{OPTION}, @var{NAME}, @var{VALUE} and
1506 @var{SOURCE} bound to the values returned by the @code{getopt-cmdline}
1507 function above. Note that @var{BODY} is not evaluated if there was no
1508 remaining option on the @cmdline{}, so you don't need to conditionalize
1509 on @var{OPTION} being @code{null} yourself.
1510 @end defmac
1512 @defmac do-cmdline-options (OPTION NAME VALUE SOURCE) BODY
1513 As above, but loop over all @cmdline{} options.
1514 @end defmac
1517 @c ----
1518 @c Help
1519 @c ----
1520 @node Help, , Option Retrieval, Using Clon
1521 @section Help
1522 @cindex Help String
1523 One of the first motivations in the design of @clon{} was to automate
1524 the generation of the help string, which is a very boring maintenance
1525 task to do by hand. The application's synopsis contains all the
1526 necessary information to do so. In order to print your application's
1527 help string, use the @code{help} function.
1529 @defun help [@code{:item} ITEM]
1530 @bioindex{search-path}
1531 @bievindex{SEARCH_PATH}
1532 @bioindex{highlight}
1533 @bievindex{HIGHLIGHT}
1534 @bioindex{theme}
1535 @bievindex{THEME}
1536 @bioindex{line-width}
1537 @bievindex{LINE_WIDTH}
1538 Print the application's help string. Printing honors the search path,
1539 theme, line width and highlight settings provided by the corresponding
1540 built-in options (@pxenduserref{Theme Mechanism}).
1541 @end defun
1543 @fkindex{help,:item}
1544 By default, @code{help} prints the whole application help string,
1545 excluding hidden items. However, if you have kept a reference to any
1546 synopsis item (option, text, group), you can pass it as the value of the
1547 @code{:item} key, and @clon{} will only print the help string for that
1548 particular item. In this case however, the hidden state of the item is
1549 discarded (but @emph{not} the ones of sub-items).
1551 @bioindex{help}
1552 @cindex Built-In Groups
1553 @cindex Groups, built-in
1554 @cindex Hidden Groups
1555 @cindex Groups, hidden
1556 For instance, the @clon{} built-in group is normally hidden, so it
1557 doesn't show up in the global help string, but the @bioption{help}
1558 option uses the @code{help} function on it explicitely, so it discards
1559 its hidden state.
1561 Here is a potentially useful application of hidden groups in conjunction
1562 with the @code{:item} key. Look at ImageMagick's @file{convert}
1563 program's help string for instance: it is 276 lines long. Gosh. The help
1564 string is decomposed into several categories: image settings, image
1565 operators, misc options @etc{}. If I were to implement this program, I
1566 would rather have the @option{--help} option display an overview of the
1567 program, advertise @option{--version} and a couple of others, and I
1568 would then implement @option{--help} as an enumeration for listing every
1569 option category individually (they would normally be stored in hidden
1570 groups). The user could then use @option{--help=settings},
1571 @option{--help=operators} and so on to display only the category she's
1572 interested in.
1574 Finally, here is potentially useful application of hidden options that
1575 are never ever displayed in any help string whatsoever, and I mean,
1576 like, ever. This is the perfect tool for backdoor'ing a program. For
1577 instance, if you ever need to implement a
1578 @option{--discard-all-security-measures-and-blow-the-nuke} option, then
1579 you'd better have it hidden@dots{}
1583 @c ====================================================================
1584 @c Extending Clon
1585 @c ====================================================================
1586 @node Extending Clon, Advanced Usage, Using Clon, Top
1587 @chapter Extending Clon
1589 As you know, @clon{} already provides seven built-in option types: flags
1590 and six other types for valued options (@pxref{Built-In Valued
1591 Options}). After using @clon{} for a while, you may find that however
1592 brilliant and perfectly designed it is, none of the provided built-in
1593 types fullfill your requirements exactly. There are two ways around
1594 this: the right way and the wrong way (hint).
1596 @voindex{Strings,stropt}
1597 The wrong, although perhaps quicker way would be to use the
1598 @code{stropt} option type to simply retrieve unprocessed string values,
1599 and then do whatever tweaking required on them. In doing so, you risk
1600 reinventing some of @clon{}'s wheels.
1602 The right way is to define a new option type. Properly defined option
1603 types are a good thing because they allow for reusability and also
1604 extensibility, since new option types can always be defined on top of
1605 others.
1606 @voindex{Enumerations,enum}
1607 In this chapter we explain how to extend @clon{} by providing new option
1608 types. We illustrate the process with the example of the built-in
1609 @code{enum} one.
1611 @cindex Valued Options
1612 @cindex Options, valued
1613 @oindex{Flags,flag}
1614 Oh, and I almost forgot. I hope it is obvious to everyone that new
1615 option types are always @emph{valued}. There's no point in extending
1616 @clon{} with options that don't take any arguments, since we already
1617 have flags.
1619 @menu
1620 * New Option Types::    In four steps
1621 * Extension Tips::      Some advice
1622 @end menu
1625 @c ----------------
1626 @c New Option Types
1627 @c ----------------
1628 @node New Option Types, Extension Tips, Extending Clon, Extending Clon
1629 @section New Option Types
1630 @cindex Option Types, in files
1631 @cindex Files, one per option type
1632 @pkgindex{com.dvlsoft.clon}
1633 From a software engineering point of view, it is better to implement new
1634 option types in a file of their own, preferably named after the option
1635 type itself, and to put this file in the @clon{} package, like this:
1637 @cartouche
1638 @verbatim
1639 (in-package :com.dvlsoft.clon)
1640 @end verbatim
1641 @end cartouche
1643 Creating your own option type involves 5 steps: providing a class for
1644 them, implementing three protocols related to argument/value tweaking,
1645 and providing a constructor function. We now review those 5 steps in
1646 order.
1648 @menu
1649 * New Option Classes::                  Step 1
1650 * Value Check Protocol::                Step 2
1651 * Argument Conversion Protocol::        Step 3
1652 * Error Management::                    In-between steps coffee time!
1653 * Value Stringification Protocol::      Step 4
1654 * Constructor Functions::               Step 5
1655 @end menu
1657 @node New Option Classes, Value Check Protocol, New Option Types, New Option Types
1658 @subsection New Option Classes
1659 @clsindex{option}
1660 @clsindex{valued-option}
1661 @clon{} maintains a class hierarchy for all option types. The mother of
1662 all option types is the @code{option} abstract class. It handles the
1663 options'short and long names, description and associated environment
1664 variable (@pxref{Common Properties}). Valued options inherit from an
1665 abstract subclass of @code{option} called @code{valued-option}. This
1666 class handles the option's argument name and status (optional or
1667 mandatory), fallback and default values (@pxref{Common Valued Option
1668 Properties}).
1670 @cindex User-Defined Option Classes
1671 @cindex Option Classes, user-defined
1672 In order to create a new option type, use the @code{defoption} macro.
1674 @defmac defoption CLASS SUPERCLASSES SLOTS &rest OPTIONS
1675 Create a new option CLASS and register it with @clon{}.
1676 Syntactically, thismacro behaves like @code{defclass}. Option types
1677 created like this implicitely inherit from @code{valued-option} and in
1678 turn @code{option}, so you don't need to put them explicitely in the
1679 @var{SUPERCLASSES} list.
1680 @end defmac
1682 Let's look at the enumeration example now.
1684 @cartouche
1685 @verbatim
1686 (defoption enum (enum-base)
1687   ((argument-name ;; inherited from the VALUED-OPTION class
1688     :initform "TYPE"))
1689   (:documentation "The ENUM class.
1690 This class implements options whose values belong to a set of keywords."))
1691 @end verbatim
1692 @end cartouche
1694 @voindex{Enumerations,enum}
1695 @vopindex{Enumerations,enum,:enum}
1696 @voindex{Extended Switches,xswitch}
1697 @vopindex{Extended Switches,xswitch,:enum}
1698 @clsindex{enum-base}
1699 As you can see, this class inherits from @code{enum-base}, which is the
1700 class handling the @code{:enum} property. The reason for this split is
1701 that there are currently two option types providing enumeration-like
1702 facility: @code{enum} and @code{xswitch}, so @code{xswitch} also
1703 inherits from @code{enum-base}.
1705 @clsindex{valued-option}
1706 @cvopindex{:argument-name}
1707 There are no new slots in this class, but the @code{argument-name} slot
1708 provided by the @code{valued-option} class has its initform changed from
1709 @code{"ARG"} to @code{"TYPE"}.
1711 @node Value Check Protocol, Argument Conversion Protocol, New Option Classes, New Option Types
1712 @subsection Value Check Protocol
1713 @cindex Value Check Protocol
1714 @cindex Protocols, value check
1715 Now that we have our new option class, we need to implement the
1716 so-called @dfn{value check} protocol. This protocol is used to make sure
1717 that values provided for options of your new type actually comply with
1718 the type in question. Values going through this protocol are fallback
1719 values, default values, and values provided from a debugger restart
1720 (@pxenduserref{Error Management}). In the case of fallback and default
1721 values (which, by the way, are provided by @emph{you}, the @clon{}
1722 user), the check is performed only once, when the option object is
1723 created. Values provided from a debugger restart come from the
1724 application end-user, and hence are checked every time.
1726 The value check protocol is implemented through a @code{check} generic
1727 function for which you must provide a method.
1729 @deffn {Generic Function} check OPTION VALUE
1730 @gfsubindex{check}
1731 @ecindex invalid-value
1732 Check that @var{VALUE} is valid for @var{OPTION}. If @var{VALUE} is
1733 valid, return it. Otherwise, raise an @code{invalid-value} error.
1734 @end deffn
1736 As you can see, you need to provide a method with the first argument
1737 specialized to your new option type. This method must return @var{VALUE}
1738 if it is okay, and raise an @code{invalid-value} error otherwise.
1740 @ecindex invalid-value
1741 @clon{} maintains a hierarchy of error conditions. The
1742 @code{invalid-value} error condition is defined like this:
1744 @cartouche
1745 @verbatim
1746 (define-condition invalid-value (option-error)
1747   ((value :documentation "The invalid value."
1748           :initarg :value
1749           :reader value)
1750    (comment :documentation "An additional comment about the error."
1751             :type string
1752             :initarg :comment
1753             :reader comment))
1754   (:report (lambda (error stream)
1755              (format stream "Option ~A: invalid value ~S.~@[~%~A~]"
1756                (option error) (value error) (comment error))))
1757   (:documentation "An invalid value error."))
1758 @end verbatim
1759 @end cartouche
1761 @ecindex invalid-value
1762 @ecsindex{invalid-value,value}
1763 @ecsindex{invalid-value,comment}
1764 When the error is raised, you must fill in the @code{value} and
1765 @code{comment} slots appropriately.
1766 @ecindex option-error
1767 @ecsindex{option-error,option}
1768 The super-condition @code{option-error} provides an additional
1769 @code{option} slot that you must also fill in when the error is raised.
1771 @gfmindex{check,@r{Enumerations (}enum@r{)}}
1772 @voindex{Enumerations,enum}
1773 @vopindex{Enumerations,enum,:enum}
1774 @findex list-to-string
1775 Let's look at the enumeration example now.
1777 @cartouche
1778 @verbatim
1779 (defmethod check ((enum enum) value)
1780   "Check that VALUE is a valid ENUM."
1781   (unless (member value (enum enum))
1782     (error 'invalid-value
1783            :option enum
1784            :value value
1785            :comment (format nil "Valid values are: ~A."
1786                       (list-to-string (enum enum)
1787                                       :key #'prin1-to-string))))
1788   value)
1789 @end verbatim
1790 @end cartouche
1792 This code should be self-explanatory. We check that the value we got
1793 belongs to the enumeration. @code{list-to-string} is a utility function
1794 that will separate every element with comas in the resulting string.
1796 @node Argument Conversion Protocol, Error Management, Value Check Protocol, New Option Types
1797 @subsection Argument Conversion Protocol
1798 @cindex Argument Conversion Protocol
1799 @cindex Protocols, argument conversion
1800 The next protocol we need to implement is the so-called @dfn{argument
1801 conversion} protocol. This protocol is used to convert option arguments
1802 (that is, strings) to an actual value of the proper type. Arguments
1803 going through this protocol come from the @cmdline{}, the value of an
1804 environment variable or a debugger restart (@pxenduserref{Error
1805 Management}). Also, note that @clon{} assumes that you implement this
1806 protocol correctly, so no value check is performed on values coming from
1807 the conversion of an argument.
1809 The conversion protocol is implemented through a @code{convert} generic
1810 function for which you must provide a method.
1812 @deffn {Generic Function} convert OPTION ARGUMENT
1813 @gfsubindex{convert}
1814 @ecindex invalid-argument
1815 Convert @var{ARGUMENT} to @var{OPTION's} value. If @var{ARGUMENT} is
1816 invalid, raise an @code{invalid-argument} error.
1817 @end deffn
1819 As you can see, you need to provide a method with the first argument
1820 specialized to your new option type. This method must return the
1821 conversion of @var{ARGUMENT} to the appropriate type if it is valid, and
1822 raise an @code{invalid-argument} error otherwise.
1824 @ecindex invalid-argument
1825 The @code{invalid-argument} error condition is defined like this:
1827 @cartouche
1828 @verbatim
1829 (define-condition invalid-argument (option-error)
1830   ((argument :documentation "The invalid argument."
1831              :type string
1832              :initarg :argument
1833              :reader argument)
1834    (comment :documentation "An additional comment about the error."
1835             :type string
1836             :initarg :comment
1837             :reader comment))
1838   (:report (lambda (error stream)
1839              (format stream "Option ~A: invalid argument ~S.~@[~%~A~]"
1840                (option error) (argument error) (comment error))))
1841   (:documentation "An invalid argument error."))
1842 @end verbatim
1843 @end cartouche
1845 @ecindex invalid-argument
1846 @ecsindex{invalid-argument,argument}
1847 @ecsindex{invalid-argument,comment}
1848 When the error is raised, you must fill in the @code{argument} and
1849 @code{comment} slots appropriately.
1850 @ecindex option-error
1851 @ecsindex{option-error,option}
1852 As before, the super-condition @code{option-error} provides an
1853 additional @code{option} slot that you must also fill in when the error
1854 is raised.
1856 @gfmindex{convert,@r{Enumerations (}enum@r{)}}
1857 @voindex{Enumerations,enum}
1858 @vopindex{Enumerations,enum,:enum}
1859 @findex closest-match
1860 Let's look at the enumeration example now.
1862 @cartouche
1863 @verbatim
1864 (defmethod convert ((enum enum) argument)
1865   "Convert ARGUMENT to an ENUM value."
1866   (or (closest-match argument (enum enum) :ignore-case t :key #'symbol-name)
1867       (error 'invalid-argument
1868              :option enum
1869              :argument argument
1870              :comment (format nil "Valid arguments are: ~A."
1871                         (list-to-string (enum enum)
1872                                         :key (lambda (value)
1873                                                (stringify enum value)))))))
1875 @end verbatim
1876 @end cartouche
1878 Since enumerations allow their arguments to be abbreviated, a utility
1879 function named @code{closest-match} is used to find the closest match
1880 between an argument and the possible values. Otherwise, an
1881 @code{invalid-argument} error is raised. For an explanation of
1882 @code{stringify}, @xref{Value Stringification Protocol}.
1884 @node Error Management, Value Stringification Protocol, Argument Conversion Protocol, New Option Types
1885 @subsection Error Management
1886 @cindex Debugger
1887 @cindex Debugger restarts
1888 Let's take a short break in our @clon{} extension process. We have seen
1889 that @clon{} may throw errors in different situations, including invalid
1890 arguments or values. The end-user manual advertises a set of debugger
1891 restarts that are available to fix those kinds of problems interactively
1892 (if you don't know what I'm talking about, please read @enduserref{Error
1893 Management} and you will know). For that reason, you are encouraged to
1894 @emph{not} disable the debugger in your standalone program, at least
1895 when you're executing @clon{} code.
1897 The way error handling is done in @cl{} standalone executables is
1898 implementation-dependent, so please refer to your favorite compiler's
1899 documentation.
1901 More generally, the behavior of @cl{} standalone executables may depend
1904 @itemize @bullet
1905 @item
1906 the state of the Lisp environment when the application was dumped, which
1907 may in turn depend on command-line options passed to the Lisp itself
1908 (@pxref{Portability}),
1909 @item
1910 @findex dump
1911 the arguments passed to the dumping function (look at @clon{}'s
1912 @code{dump} macro to see what it does),
1913 @item
1914 worse: @emph{both}.
1915 @end itemize
1917 No, really, @cl{} is no fun at all.
1919 @node Value Stringification Protocol, Constructor Functions, Error Management, New Option Types
1920 @subsection Value Stringification Protocol
1921 Okay, back to implementing our new option type.
1923 @cindex Value Stringification Protocol
1924 @cindex Protocols, value stringification
1925 The third and last protocol we need to implement is called the
1926 @dfn{value stringification} protocol. This protocol can be seen as the
1927 reverse protocol for argument conversion (@pxref{Argument Conversion
1928 Protocol}): its purpose is to transform an option's value into a
1929 corresponding argument that the end-user could have provided in order to
1930 get that value.
1932 @cindex Help String
1933 @cvopindex{:fallback-value}
1934 @cindex Values, source, fallback
1935 @cvopindex{:default-value}
1936 @cindex Values, source, default
1937 @gfmindex{convert,@r{Enumerations (}enum@r{)}}
1938 The main use for this protocol is to advertise the fallback and default
1939 values correctly in help strings: the end-user does not want to see
1940 those @emph{values}, but rather the @emph{argument} that would lead to
1941 them. However, you are free to use it wherever you like (see the
1942 @code{convert} method for @code{enum} options for instance).
1944 The value stringification protocol is implemented through a
1945 @code{stringify} generic function for which you must provide a method.
1947 @deffn {Generic Function} stringify OPTION VALUE
1948 @gfsubindex{stringify}
1949 Transform OPTION's @var{VALUE} into an argument.
1950 @end deffn
1952 I admit that this function could also have been called
1953 @code{argumentize} or even @code{deconvertify}. As you can see, you need
1954 to provide a method with the first argument specialized to your new
1955 option type. You can assume that @var{VALUE} is a valid value for your
1956 option, so no checking is necessary and no error needs to be raised.
1958 @gfmindex{stringify,@r{Enumerations (}enum@r{)}}
1959 @voindex{Enumerations,enum}
1960 Let's look at the enumeration example now.
1962 @cartouche
1963 @verbatim
1964 (defmethod stringify ((enum enum) value)
1965   "Transform ENUM's VALUE into an argument."
1966   (string-downcase (symbol-name value)))
1967 @end verbatim
1968 @end cartouche
1970 Pretty straightforward, right?
1973 @node Constructor Functions, , Value Stringification Protocol, New Option Types
1974 @subsection Constructor Functions
1975 @cindex Constructors, for options objects
1976 @cindex Option Constructors
1977 The last required step to complete our new option type extension is to
1978 provide a @dfn{constructor} function that wraps around
1979 @code{make-instance} on the corresponding option class. I won't insult
1980 you by explaining how to write a constructor. Let me just give four good
1981 reasons why providing constructors is important.
1983 Providing a constructor for every new option type is important because:
1984 @enumerate
1985 @item
1986 it is important,
1987 @item
1988 it is a good software engineering practice,
1989 @item
1990 it is important,
1991 @item
1992 @findex defsynopsis
1993 @findex defgroup
1994 and above all, it makes your new option type automatically available in
1995 calls to @code{defsynopsis} and @code{defgroup} (@pxref{Synopsis Items}
1996 and @ref{Group Definition}).
1997 @end enumerate
2000 @voindex{Enumerations,enum}
2001 @cfindex{make-enum}
2002 Let's look at the enumeration example now.
2004 @cartouche
2005 @verbatim
2006 (defun make-enum (&rest keys
2007                   &key short-name long-name description
2008                        argument-name argument-type
2009                        enum env-var fallback-value default-value
2010                        hidden)
2011   "Make a new enum option.
2012 - SHORT-NAME is the option's short name (without the dash).
2013   It defaults to nil.
2014 - LONG-NAME is the option's long name (without the double-dash).
2015   It defaults to nil.
2016 - DESCRIPTION is the option's description appearing in help strings.
2017   It defaults to nil.
2018 - ARGUMENT-NAME is the option's argument name appearing in help strings.
2019 - ARGUMENT-TYPE is one of :required, :mandatory or :optional (:required and
2020   :mandatory are synonyms).
2021   It defaults to :optional.
2022 - ENUM is the set of possible values.
2023 - ENV-VAR is the option's associated environment variable.
2024   It defaults to nil.
2025 - FALLBACK-VALUE is the option's fallback value (for missing optional
2026   arguments), if any.
2027 - DEFAULT-VALUE is the option's default value, if any.
2028 - When HIDDEN, the option doesn't appear in help strings."
2029   (declare (ignore short-name long-name description
2030                   argument-name argument-type
2031                   enum env-var fallback-value default-value
2032                   hidden))
2033   (apply #'make-instance 'enum keys))
2034 @end verbatim
2035 @end cartouche
2037 Woah, what a mouthful for a single line of code@dots{} Yeah, I'm a
2038 maniac and I like redundancy. I always restate all the available keys
2039 explicitely, and everything again in the docstring so that all the
2040 interesting information is directly available (I might change my mind as
2041 I grow older though).
2044 @c --------------
2045 @c Extension Tips
2046 @c --------------
2047 @node Extension Tips, , New Option Types, Extending Clon
2048 @section Extension Tips
2049 So that's it. Now you know how to extend @clon{} with your own option
2050 types. Here is some piece of advice that you might find useful in the
2051 process.
2053 @menu
2054 * Incremental Option Types::    Doing without defoption
2055 * Lisp Option Abuse::           Thinking in end-user terms
2056 @end menu
2058 @node Incremental Option Types, Lisp Option Abuse, Extension Tips, Extension Tips
2059 @subsection Incremental Option Types
2060 @findex defoption
2061 If one of the built-in options is almost what you need, you may be
2062 tempted to subclass it directly instead of using @code{defoption}, and
2063 only change what's needed, After all, it's Lisp. Lisp is a world of
2064 mess@t{^D^D^D^D}freedom.
2066 Wrong.
2068 @findex defsynopsis
2069 @findex defgroup
2070 @code{defoption} is not @emph{only} a convenience wrapper around
2071 @code{defclass}. It also arranges for @code{defsynopsis} and
2072 @code{defgroup} to recognize your new option type. So please, do use it
2073 systematically.
2075 @node Lisp Option Abuse, , Incremental Option Types, Extension Tips
2076 @subsection Lisp Option Abuse
2077 @voindex{Lisp Objects,lispobj}
2078 @vopindex{Lisp Objects,lispobj,:typespec}
2079 Along with the same lines, you may find that the @code{lispobj} type is
2080 all you need in many situations. Let's take an example. Suppose you want
2081 to implement a @code{--stars} option to assign a rank to a movie, from 0
2082 to 5. The lazy approach is to simply create a @code{lispobj} option with
2083 a @code{:typespec} (type specifier) of @code{(integer 0 5)} and you're
2084 done.
2086 But now, remember that the end-user of your application is probably not
2087 a Lisper (in fact, I would hope that @clon{} contributes to increasing
2088 the number of standalone @cl{} applications out there@dots{}). What do
2089 you think would be her reaction, if, after providing a bogus value to
2090 the @code{--stars} option, she get the following error message:
2092 @verbatim
2093  Option 'stars': invalid argument "6".
2094 Argument "6" must evaluate to (integer 0 5).
2095 @end verbatim
2097 or worse, a @code{"Cannot parse argument"} error message because of a
2098 typo?
2100 Not very friendly, right? In other words, you need to think in terms of
2101 what the end-user of your application will expect. In that particular
2102 situation, you might want to subclass @code{lispobj} (with
2103 @code{defoption}!) only to provide friendlier error messages.
2107 @c ====================================================================
2108 @c Advanced Usage
2109 @c ====================================================================
2110 @node Advanced Usage, Conclusion, Extending Clon, Top
2111 @chapter Advanced Usage
2113 This chapter contains information about different features that are
2114 present in @clon{} because of design decisions, but that I expect to be
2115 used only rarely, if at all.
2117 @menu
2118 * Multiple Clon Instances::     Different command-lines, synopsis or contexts
2119 * Programmatic Help Strings::   Beyond the --help option
2120 * Version Numbering::           In case you need to conditionalize
2121 @end menu
2124 @c -----------------------
2125 @c Multiple Clon Instances
2126 @c -----------------------
2127 @node Multiple Clon Instances, Programmatic Help Strings, Advanced Usage, Advanced Usage
2128 @section Multiple @clon{} Instances
2130 It is possible to use different instances of @clon{} in parallel in a
2131 single application, by using a virtual @cmdline{} instead of the real
2132 one, different synopsis and multiple contexts simultaneously.
2134 @menu
2135 * Using Different Synopsis::            The default one, and the others
2136 * Using Different Command-Lines::       The real one, and the others
2137 * Using Multiple Contexts::             The current one, and the others
2138 * Potential Uses::                      What to do with all that
2139 @end menu
2141 @node Using Different Synopsis, Using Different Command-Lines, Multiple Clon Instances, Multiple Clon Instances
2142 @subsection Using Different Synopsis
2143 @cindex Synopsis, default
2144 Did you notice that after defining a synopsis, there is actually never
2145 any explicit reference to it anymore? So where is the magick? In fact,
2146 there's no magick at all involved here.
2148 @vindex *default-synopsis*
2149 @foindex{defsynopsis,:make-default}
2150 @cfiaindex{make-synopsis,:make-default}
2151 @clon{} has a global variable named @code{*default-synopsis*} which
2152 holds the@dots{} default synopsis, yeah. When you define/create a
2153 synopsis with either @code{defsynopsis} or @code{make-synopsis}, it is
2154 automatically made the default one, unless you use the
2155 @code{:make-default} option/initarg with a value of @code{nil}, like
2156 this:
2158 @verbatim
2159 (defsynopsis (:make-default nil) ...)
2160 @end verbatim
2162 or this:
2164 @verbatim
2165 (make-synopsis :make-default nil ...)
2166 @end verbatim
2168 @cfindex{make-context}
2169 When you create a context with @code{make-context}, the default synopsis
2170 is used implicitely, but you have two ways to avoid this.
2172 @enumerate
2173 @item
2174 @vindex *default-synopsis*
2175 At any time in your program, you may change the value of
2176 @code{*default-synopsis*}. All subsequent calls to @code{make-context}
2177 will hence use this other synopsis.
2178 @item
2179 @cfiaindex{make-context,:synopsis}@c
2180 If you prefer to use another synopsis only temporarily, you can use the
2181 @code{:synopsis} initarg to @code{make-context} instead.
2182 @end enumerate
2184 @node Using Different Command-Lines, Using Multiple Contexts, Using Different Synopsis, Multiple Clon Instances
2185 @subsection Using Different Command-Lines
2186 In @ref{Context Creation}, we saw that a context object describes a
2187 particular instance of your application, most notably depending on the
2188 actual @cmdline{} the end-user provided. It turns out, however that the
2189 @cmdline{} doesn't need to be the actual program's @cmdline{}, as the
2190 user typed it. Any list of strings can act as a @cmdline{}.
2192 @cfiaindex{make-context,:cmdline}
2193 The function @code{make-context} has a @code{:cmdline} key that allows
2194 you to provide any list of strings that will act as the @cmdline{}. Of
2195 course, the default is to use the actual program's one.
2197 @node Using Multiple Contexts, Potential Uses, Using Different Command-Lines, Multiple Clon Instances
2198 @subsection Using Multiple Contexts
2199 @cindex Context, current
2200 Did you also notice that after creating a context, there is actually
2201 never any explicit reference to it anymore? So again, where is the
2202 magick? In fact, there's no magick at all involved here either.
2204 @vindex *current-context*
2205 @cfiaindex{make-context,:make-current}
2206 @clon{} has a global variable named @code{*current-context*} which holds
2207 the@dots{} current context, yeah. When you create a context with
2208 @code{make-context}, it is automatically made current, unless you use
2209 the @code{:make-current} initarg with a value of @code{nil}.
2211 @cindex Runtime Phase
2212 @findex progname
2213 @findex remainder
2214 @findex getopt
2215 @findex getopt-cmdline
2216 @findex multiple-value-getopt-cmdline
2217 @findex do-cmdline-options
2218 @findex help
2219 The whole runtime phase API of @clon{} uses a context implicitely. This
2220 involves @code{progname}, @code{remainder}, @code{getopt},
2221 @code{getopt-cmdline}, @code{multiple-value-getopt-cmdline},
2222 @code{do-cmdline-options} and @code{help}. As a consequence, it is
2223 possible to use @clon{} with multiple contexts at the same time. There
2224 are in fact three ways to achieve this.
2226 @enumerate
2227 @item
2228 @vindex *current-context*
2229 At any time in your program, you may change the value of
2230 @code{*current-context*}. All subsequent calls to the runtime phase API
2231 will hence use this other context.
2232 @item
2233 @clon{} also provides a macro which changes the current context for you.
2234 @defun with-context CONTEXT &body BODY
2235 Execute @var{BODY} with @code{*current-context*} bound to @var{CONTEXT}.
2236 @end defun
2237 @item
2238 @fkindex{progname,:context}@c
2239 @fkindex{remainder,:context}@c
2240 @fkindex{getopt,:context}@c
2241 @fkindex{getopt-cmdline,:context}@c
2242 @fkindex{help,:context}@c
2243 @foindex{multiple-value-getopt-cmdline,:context}@c
2244 @foindex{do-cmdline-options,:context}@c
2245 If you prefer to use another context only once, you can use the
2246 @code{:context} key instead. The whole runtime phase API of @clon{}
2247 understands it. For the functions @code{getopt}, @code{getopt-cmdline}
2248 and @code{help}, it's just another key in addition to those we've
2249 already seen. For the macros @code{multiple-value-getopt-cmdline} and
2250 @code{do-cmdline-options}, the key must appear at the end of the first
2251 (list) argument, like this:
2253 @verbatim
2254 (multiple-value-getopt-cmdline (option name value :context ctx) ...)
2255 (do-cmdline-options (option name value :context ctx) ...)
2256 @end verbatim
2257 @end enumerate
2259 @node Potential Uses, , Using Multiple Contexts, Multiple Clon Instances
2260 @subsection Potential Uses
2261 By combining @clon{}'s ability to use a virtual @cmdline{}, different
2262 synopsis and multiple contexts, you can achieve very neat (read: totally
2263 useless) things. For instance, you could write an application that takes
2264 an option providing @cmdline{} arguments for an external program to be
2265 forked. Some revision control systems do that for controlling external
2266 @code{diff} programs for instance, so no big deal. The big deal is that
2267 you can completely control the validity of the external program's
2268 @cmdline{}, before it is forked, from your original one.
2270 Here is another idea, again related to revision control systems. Some of
2271 them feature a @cmdline{} syntax like the following:
2273 @verbatim
2274 prog [global options] command [command-specific options]
2275 @end verbatim
2277 @cindex Postfix
2278 @cindex Command-Line, remainder
2279 @cindex Remainder, of command-line
2280 You can achieve this with @clon{} quite easily. In fact, the
2281 demonstration program called @file{advanced} in the distribution shows
2282 you how to do it. First, define a synopsis which only handles the global
2283 options, and provide a postfix of @code{"command [command-specific
2284 option]"} or something like that. This will authorize a @cmdline{}
2285 remainder which will start with the command name.
2287 Now, for every command in your program, define a specific synopsis with
2288 only the command-specific options. Get the remainder of the original
2289 @cmdline{} (@pxref{Command-Line Remainder}) and figure out which command
2290 was used. Depending on it, create a new context with the appropriate
2291 synopsis and the original @cmdline{}'s remainder as the new, virtual,
2292 @cmdline{}. You're done: retrieve global options from the first context,
2293 and command-specific ones from the second one.
2295 @cindex Help String, display
2296 @findex help
2297 What's even cooler is that you can display the command-specific options
2298 on demand quite easily as well (like what @file{git} does when you call
2299 it like this: @code{git commit --help} for instance): calling the
2300 @code{help} function on the original context gives you the global
2301 options's help string while calling it on the command-specific one will
2302 display the command-specific usage.
2304 @bioindex{search-path}
2305 @bievindex{SEARCH_PATH}
2306 @bioindex{highlight}
2307 @bievindex{HIGHLIGHT}
2308 @bioindex{theme}
2309 @bievindex{THEME}
2310 @bioindex{line-width}
2311 @bievindex{LINE_WIDTH}
2312 One thing to remember here is that every context/synopsis duet you
2313 create gets its own set of built-in @clon{} options. As a consequence,
2314 there is currently no simple way to have a single set of built-in
2315 options apply to the whole application, for instance, to both a global
2316 and a command-specific context. Let me make this clearer: if your
2317 end-user calls @code{prog --clon-theme=foo command -h}, then the theme
2318 option will have no effect because it would only affect the global help
2319 option. In order to actually use the expected theme, your end-user would
2320 need to use @code{prog command --clon-theme=foo -h}. Depending on which
2321 cerebral emisphere (s)he prefers to use, this may seem logical or not.
2323 Finally, note that you can use the virtual @cmdline{} / specific
2324 synopsis technique recursively to manage complicated @cmdline{} syntax,
2325 for instance alternating options and non-options parts several times.
2327 In the future, @clon{} may provide better ways to achieve this kind of
2328 things (a notion of ``sub-context'' may be in order).
2332 @c -------------------------
2333 @c Programmatic Help Strings
2334 @c -------------------------
2335 @node Programmatic Help Strings, Version Numbering, Multiple Clon Instances, Advanced Usage
2336 @section Programmatic Help Strings
2338 @findex help
2339 @cindex Help String
2340 @cindex Themes
2341 @cindex Themes, standard, @t{refcard}
2342 @cindex Standard Themes, @t{refcard}
2343 So far, we've seen how to use the @code{help} function to implement a
2344 typical @code{--help} option. This is mostly intended for the end-user.
2345 There are also times when this function could be useful to @emph{you},
2346 the application developer. For instance, one could imagine that part of
2347 the compilation phase would involve generating the help string in order
2348 to include it in the manual. Another idea would be that @samp{make
2349 install} creates a @file{REFCARD} file in
2350 @file{/usr/local/share/doc/my-app/} which contains the help string
2351 formatted with the @code{refcard} theme, @etc{}.
2353 @bioindex{theme}
2354 @bievindex{THEME}
2355 @bioindex{search-path}
2356 @bievindex{SEARCH_PATH}
2357 @bioindex{line-width}
2358 @bievindex{LINE_WIDTH}
2359 @bioindex{highlight}
2360 @bievindex{HIGHLIGHT}
2361 In such situations, calling the @code{help} function might not be
2362 directly associated with an end-user level option, or at least not
2363 @code{--help}, and you might not want to honor the end-user level
2364 settings for theme, search path, line-width, or highlighting either
2365 (remember that these settings might come from the environment variables
2366 associated with @bioption{theme}, @bioption{search-path},
2367 @bioption{line-width} and @bioption{highlight}).
2369 @fkindex{help,:theme}
2370 @fkindex{help,:search-path}
2371 @fkindex{help,:line-width}
2372 @fkindex{help,:highlight}
2373 Because of this, the @code{help} function provides additional keys that
2374 allow you to override those settings (they are in fact stored in the
2375 context object). The keys in question are: @code{:theme},
2376 @code{:search-path}, @code{:line-width} and @code{:highlight}.
2378 @fkindex{help,:output-stream}
2379 @vindex *standard-output*
2380 In addition to that, there is an @code{:output-stream} key which
2381 defaults to @code{*standard-output*} which you could use for instance to
2382 write directly to a file. Note that there is no end-user level access to
2383 this parameter.
2387 @c -----------------
2388 @c Version Numbering
2389 @c -----------------
2390 @node Version Numbering, , Programmatic Help Strings, Advanced Usage
2391 @section Version Numbering
2393 @bioindex{version}
2394 As @clon{} evolves over time, you might one day feel the need for
2395 conditionalizing your code on the version of the library. While the
2396 end-user of your application has limited means to access the current
2397 version number of @clon{} (see @enduserref{Clonification} and the
2398 built-in option @bioption{version}), you, the application programmer
2399 and @clon{} user, have a finer grained access to it.
2401 The first thing you can do to access the current version number of
2402 @clon{} is use the @code{version} function (this is in fact the function
2403 bound to the @bioption{version} option).
2405 @defun version &optional (TYPE :number)
2406 Return the current version number of @clon{}. @var{TYPE} can be one of
2407 @code{:number}, @code{:short} or @code{:long}. For @code{:number}, the
2408 returned value is a fixnum. Otherwise, it is a string.
2409 @end defun
2411 A @clon{} version is characterized by 4 elements as described below.
2412 @itemize
2413 @item
2414 @vindex +release-major-level+
2415 A major version number stored in the constant
2416 @code{+release-major-level+}.
2417 @item
2418 @vindex +release-minor-level+
2419 A minor version number, stored in the constant
2420 @code{+release-minor-level+}.
2421 @item
2422 @vindex +release-status+
2423 A release status stored in the constant @code{+release-status+}. The
2424 status of a release can be @code{:alpha}, @code{:beta}, @code{:rc}
2425 (standing for ``release candidate'') or @code{:patchlevel}. These are in
2426 effect 4 levels of expected stability.
2427 @item
2428 @vindex +release-status-level+
2429 A status-specific version number stored in the constant
2430 @code{+release-status-level+}. Status levels start at 1 (alpha 1, beta 1
2431 and release candidate 1) except for stable versions, in which case patch
2432 levels start at 0 (@eg{} 2.4.0).
2433 @end itemize
2435 @vindex +release-name+
2436 In addition to that, each version of @clon{} (in the sense
2437 @emph{major.minor}, regardless of the status) has a name, stored in the
2438 constant @code{+release-name+}. The general theme for @clon{} is ``Great
2439 Jazz Musicians'', and specifically for the 1.x series: ``Great Saxophone
2440 Players''. Anyone daring to mention Kenny G at that point will be shot
2441 on sight.
2443 Here is how the @code{version} function computes its value.
2444 @itemize
2445 @item
2446 A version @code{:number} is computed as @emph{major . 10000 + minor .
2447 100 + patchlevel}, effectively leaving two digits for each level. Note
2448 that alpha, beta and release candidate status are ignored in version
2449 numbers (this is as if the corresponding status level was considered to
2450 be always 0). Only stable releases have their level taken into account.
2451 @item
2452 A @code{:short} version will appear like this for unstable releases:
2453 1.3a4, 2.5b8 or 4.2rc1. Remember that alpha, beta or release candidate
2454 levels start at 1. Patchlevels for stable releases start at 0 but 0 is
2455 ignored in the output. So for instance, version 4.3.2 will appear as-is,
2456 while version 1.3.0 will appear as just 1.3.
2457 @item
2458 A @code{:long} version is expanded from the short one, and includes the
2459 release name. For instance, 1.3 alpha 4 "Bill Evans", 2.5 beta 8 "Scott
2460 Henderson", 4.2 release candidate 1 "Herbie Hancock" or 4.3.2 "Chick
2461 Corea". As for the short version, a patchlevel of 0 is ignored in the
2462 output: 1.3 "Bill Evans".
2463 @end itemize
2467 @c ====================================================================
2468 @c Conclusion
2469 @c ====================================================================
2470 @node Conclusion, Portability, Advanced Usage, Top
2471 @chapter Conclusion
2473 So that's it I guess. You know all about @clon{} now. The next step is
2474 to actually use it to clonify your favorite application, write new
2475 applications using it and contaminate the world with standalone @cl{}
2476 programs, featuring unprecedented @cmdline{} power and thrill-a-minute
2477 option hacking.
2479 Now, go Luke. The Attack of the @clon{} is ready to begin.
2483 @c ====================================================================
2484 @c Portability
2485 @c ====================================================================
2486 @node Portability, API Quick Reference, Conclusion, Top
2487 @appendix Portability
2489 @clon{} is mostly portable and has virtually no dependency at all, by
2490 design. There are a couple of spots however where portability might be a
2491 direct concern for you.
2493 @menu
2494 * Supported Environments::      Systems, compilers and dependencies
2495 * Dumping Executables::         Convenience wrappers
2496 @end menu
2499 @c ----------------------
2500 @c Supported Environments
2501 @c ----------------------
2502 @node Supported Environments, Dumping Executables, Portability, Portability
2503 @section Supported Environments
2504 @clon{} currently works on Unix systems (including MacOS X) and has been
2505 ported to 6 @cl{} implementations. I have no idea about Windows right
2506 now. The following table lists the supported environments.
2508 @multitable {Compiler} {Minimum Version} {@code{cffi} (optional)}
2509 @headitem Compiler @tab Minimum Version @tab Dependencies
2510 @item SBCL
2511 @tab
2512 @tab
2513 @item CMU-CL
2514 @tab 20b
2515 @tab
2516 @item CCL
2517 @tab
2518 @tab
2519 @item ECL
2520 @tab
2521 @tab
2522 @item CLISP
2523 @tab
2524 @tab @code{cffi} (optional)
2525 @item ABCL
2526 @tab 0.24.0@footnote{more precisely, svn trunk revision 13156}
2527 @tab
2528 @end multitable
2530 @unnumberedsubsec ABCL specificities
2531 @clon{}'s ABCL port currently has two limitations:
2532 @itemize @bullet
2533 @item
2534 @bioindex{highlight}@c
2535 @bioindex{line-width}@c
2536 @evindex{COLUMNS}@c
2537 Terminal autodetection is not supported. This means that
2538 @bioption{highlight=auto} doesn't work (highlighting is @emph{not}
2539 turned on automatically on a @tty{}). For the same reason, unless
2540 otherwise specified via either the @code{COLUMNS} environment variable
2541 or the @bioption{line-width} option, terminal output will be formatted
2542 for 80 columns regardless of the actual width (@pxenduserref{Global
2543 Control}).
2544 @item
2545 Since Java doesn't have a @code{putenv} or @code{setenv} function (!!),
2546 the @code{modify-environment} restart, normally proposed when an
2547 environment variable is set to a bogus value, is unavailable
2548 (@pxenduserref{Error Management}).
2549 @end itemize
2551 @unnumberedsubsec CLISP specificities
2552 As mentioned in the above table, CLISP's dependency on @code{cffi} is
2553 optional. CLISP needs @code{cffi} in order to implement terminal
2554 autodetection only. If @code{cffi} cannot be found when the ASDF system
2555 is loaded, you get a big red blinking light and a warning but that's
2556 all. @clon{} will still work, although exhibiting the same limitation as
2557 ABCL (see above).
2560 @c -------------------
2561 @c Dumping Executables
2562 @c -------------------
2563 @node Dumping Executables, , Supported Environments, Portability
2564 @section Dumping Executables
2566 Creating standalone executables is orthogonal to @clon{}. @clon{} is
2567 just a library that you might want to use, and in fact, it is also
2568 possible to use it without dumping executables at all.
2570 @findex exit
2571 @findex dump
2572 Unfortunately, there is no standard way to dump executables from Lisp.
2573 We're entering the portability mine field here. @clon{}, however, wants
2574 to help. We've already seen that it provides utility wrappers like
2575 @code{exit} and @code{dump} to make your life easier (I mean, more
2576 portable) in @ref{Quick Start}. If you're not interested in portability
2577 or if you prefer to do it your own way, you don't @emph{need} to use
2578 those wrappers. If you do, however, please read on.
2580 Continuing on the quickstart example, the table below provides
2581 ready-to-use @cmdline{} samples for dumping the program with the
2582 compilers currently supported. Remember that they work in conjunction
2583 with the @code{dump} macro mentionned above.
2585 @table @strong
2586 @item SBCL
2587 @code{CC=gcc sbcl --script quickstart.lisp}@*
2588 The @code{CC=gcc} bit is needed for the @code{sb-grovel} contrib module
2589 that @clon{} uses. However, using @code{--script} like this is in fact
2590 not recommended because it disables the debugger (@pxref{Error
2591 Management}). Instead, you might be better off doing:
2592 @verbatim
2593 CC=gcc sbcl \
2594   --disable-ldb --lose-on-corruption --end-runtime-options \
2595   --no-userinit --no-sysinit --load quickstart.lisp
2596 @end verbatim
2597 @item CMUCL
2598 @code{lisp -noinit -nositeinit -load quickstart.lisp}
2599 @item CCL
2600 @code{ccl --no-init --load quickstart.lisp}
2601 @item ECL
2602 ECL doesn't work like the other Lisp compilers. In particular, creating
2603 an executable does not involve dumping a Lisp image, but compiling the
2604 source into separate object files and then linking them. The consequence
2605 is that there is no simple @cmdline{} recipe to show here. Instead, you
2606 might want to look at the file @file{demos/dump.lisp} in the
2607 distribution for an example.
2609 Because the dumping scheme is different with ECL, it is also less
2610 straightforward to write portable code for standalone applications. The
2611 demo programs in the distribution both contain comments that are worth
2612 reading at the top of them.
2614 @findex dump
2615 One specific difference between ECL and the other Lisp compilers is that
2616 it doesn't require you to specify a particular function as the entry
2617 point for your executable, but instead relies on having code to execute
2618 directly at the toplevel of some file. @clon{}'s @code{dump} macro helps
2619 you with this: it normally expands to a compiler-specific function which
2620 saves the current Lisp image, but for ECL, it simply expands to the
2621 ``main'' function call, hence consituting the entry point to the code
2622 that ECL needs.
2623 @item CLISP
2624 @code{CC=gcc clisp -norc -i quickstart.lisp}@*
2625 The @code{CC=gcc} bit lets you choose your preferred C compiler for
2626 @code{cffi}. Please note that executables dumped (the @clon{} way) by
2627 CLISP still understand lisp-specific command-line options when they are
2628 prefixed with @code{--clisp-}, so you should obviously avoid defining
2629 options by those names.
2630 @item ABCL
2631 ABCL is a totally different beast because it's a Java-based @cl{}
2632 implementation. Most notably, you don't create standalone executables in
2633 Java, so the normal way of running ABCL is by telling it to load some
2634 lisp code. If you want to run the quickstart program in the usual way,
2635 you will typically type this:
2636 @verbatim
2637 abcl --noinform --noinit --nosystem --load quickstart.lisp
2638 @end verbatim
2639 Note that for this to work, the @code{dump} macro expands to the
2640 ``main'' function call for ABCL, just as for ECL.
2642 There's more to it than that though. It is possible to get closer to
2643 standalone executables with ABCL by 1/ providing your whole application
2644 in a @code{jar} file directly, and 2/ overriding ABCL's entry point by
2645 providing your own interpreter which runs your main function
2646 automatically.
2648 @vindex com.dvlsoft.clon.dump
2649 @clon{} helps you to do this to some extend. If the variable
2650 @code{com.dvlsoft.clon.dump} is bound in the @code{cl-user} package,
2651 then the @code{dump} macro doesn't expand to a call to the ``main''
2652 function, but instead dumps a Java file containing an alternate ABCL
2653 interpreter that you can compile and add to the original ABCL @code{jar}
2654 file, along with @file{quickstart.lisp}. If you want more details on
2655 this, you will need to look at the @file{Makefile} in the @code{demo}
2656 directory.
2657 @end table
2661 @c ====================================================================
2662 @c API Quick Reference
2663 @c ====================================================================
2664 @node API Quick Reference, Indexes, Portability, Top
2665 @appendix API Quick Reference
2667 @menu
2668 * Utilities::                   Miscellaneous stuff
2669 * Initialization Phase API::    Synopsis, items and context creation
2670 * Runtime Phase API::           Option retrieval and help formatting
2671 * Extension API::               New option types
2672 * Versioning API::              Release identification
2673 @end menu
2676 @c ---------
2677 @c Utilities
2678 @c ---------
2679 @node Utilities, Initialization Phase API, API Quick Reference, API Quick Reference
2680 @section Utilities
2682 @defmac dump NAME FUNCTION
2683 See @ref{Quick Start}.
2684 @end defmac
2686 @defun exit &optional (STATUS 0)
2687 See @ref{Quick Start}.
2688 @end defun
2690 @cindex Command-Line
2691 @defun cmdline
2692 See @ref{Option Retrieval}.
2693 @end defun
2695 @cindex Package, nicknames
2696 @defun nickname-package &optional NICKNAME
2697 See @ref{Quick Start}.
2698 @end defun
2701 @c ------------------------
2702 @c Initialization Phase API
2703 @c ------------------------
2704 @node Initialization Phase API, Runtime Phase API, Utilities, API Quick Reference
2705 @section Initialization Phase API
2707 @defun make-text &key CONTENTS HIDDEN
2708 @cfsubindex{make-text}
2709 @cfiaindex{make-text,:contents}
2710 @cfiaindex{make-text,:hidden}
2711 @defunx make-@var{OPTION} :INITARG INITVAL@dots{}
2712 @cfsubindex{make-@var{OPTION}}
2713 @cfindex make-flag
2714 @cfindex make-stropt
2715 @cfindex make-lispobj
2716 @cfindex make-enum
2717 @cfindex make-path
2718 @cfindex make-switch
2719 @cfindex make-xswitch
2720 @defunx make-group &key HEADER HIDDEN ITEM
2721 @cfsubindex{make-group}
2722 @cfiaindex{make-group,:header}
2723 @cfiaindex{make-group,:hidden}
2724 @cfiaindex{make-group,:item}
2725 @defunx make-synopsis &key POSTFIX ITEM (MAKE-DEFAULT t)
2726 @cfsubindex{make-synopsis}
2727 @cfiaindex{make-synopsis,:postfix}
2728 @cfiaindex{make-synopsis,:item}
2729 @cfiaindex{make-synopsis,:make-default}
2730 See @ref{Constructors} and @ref{Using Different Synopsis}.
2731 @end defun
2733 @defmac defgroup (&key HEADER HIDDEN) &body FORMS
2734 @foindex{defgroup,:header}
2735 @foindex{defgroup,:hidden}
2736 @xref{Group Definition}.
2737 @end defmac
2739 @defmac defsynopsis (&key POSTFIX MAKE-DEFAULT) &body FORMS
2740 @foindex{defsynopsis,:postfix}
2741 @foindex{defsynopsis,:make-default}
2742 @fiindex{defsynopsis,text}
2743 @fiindex{defsynopsis,options}
2744 @fiindex{defsynopsis,group}
2745 See @ref{Synopsis Definition} and @ref{Using Different Synopsis}.
2746 @end defmac
2748 @defopt *default-synopsis*
2749 @xref{Using Different Synopsis}.
2750 @end defopt
2752 @defun make-context &key (SYNOPSIS *default-synopsis*) CMDLINE @
2753 (MAKE-CURRENT t)
2754 @cfsubindex{make-context}
2755 @cfiaindex{make-context,:synopsis}
2756 @cfiaindex{make-context,:cmdline}
2757 @cfiaindex{make-context,:make-current}
2758 @xref{Context Creation}, @ref{Using Different Synopsis} and @ref{Using
2759 Different Command-Lines}.
2760 @end defun
2764 @c -----------------
2765 @c Runtime Phase API
2766 @c -----------------
2767 @node Runtime Phase API, Extension API, Initialization Phase API, API Quick Reference
2768 @section Runtime Phase API
2770 @defopt *current-context*
2771 @xref{Using Multiple Contexts}.
2772 @end defopt
2774 @defun with-context CONTEXT &body BODY
2775 @xref{Using Multiple Contexts}.
2776 @end defun
2778 @defun progname &key (CONTEXT *current-context*)
2779 @fkindex{progname,:context}
2780 See @ref{Contextual Information} and @ref{Using Multiple Contexts}.
2781 @end defun
2783 @defun remainder &key (CONTEXT *current-context*)
2784 @fkindex{remainder,:context}
2785 See @ref{Contextual Information} and @ref{Using Multiple Contexts}.
2786 @end defun
2788 @defun getopt &key (CONTEXT *current-context*) SHORT-NAME LONG-NAME @
2789 OPTION
2790 @fkindex{getopt,:context}
2791 @fkindex{getopt,:short-name}
2792 @fkindex{getopt,:long-name}
2793 @fkindex{getopt,:option}
2794 @vindex *current-context*
2795 See @ref{Explicit Retrieval} and @ref{Using Multiple Contexts}.
2796 @end defun
2798 @defun getopt-cmdline &key (CONTEXT *current-context*)
2799 @fkindex{getopt-cmdline,:context}
2800 @vindex *current-context*
2801 See @ref{Sequential Retrieval} and @ref{Using Multiple Contexts}.
2802 @end defun
2804 @defmac multiple-value-getopt-cmdline (OPTION NAME VALUE SOURCE &key CONTEXT) @
2805 &body BODY
2806 @defmacx do-cmdline-options (OPTION NAME VALUE SOURCE &key CONTEXT) @
2807 &body BODY
2808 @foindex{multiple-value-getopt-cmdline,:context}
2809 @foindex{do-cmdline-options,:context}
2810 See @ref{Sequential Retrieval} and @ref{Using Multiple Contexts}.
2811 @end defmac
2813 @deffn Reader short-name OPTION
2814 @rfsubindex{short-name}
2815 @deffnx Reader long-name OPTION
2816 @rfsubindex long-name
2817 @xref{Sequential Retrieval}.
2818 @end deffn
2820 @defun help &key (CONTEXT *current-context*) @
2821 (ITEM (synopsis context)) @
2822 (OUTPUT-STREAM *standard-output*) @
2823 (SEARCH-PATH (search-path context)) @
2824 (THEME (theme context)) @
2825 (LINE-WIDTH (line-width context)) @
2826 (HIGHLIGHT (highlight context)))
2827 @fkindex{help,:context}
2828 @fkindex{help,:item}
2829 @fkindex{help,:output-stream}
2830 @fkindex{help,:theme}
2831 @fkindex{help,:search-path}
2832 @fkindex{help,:line-width}
2833 @fkindex{help,:highlight}
2834 @vindex *current-context*
2835 @vindex *standard-output*
2836 @xref{Help}, @ref{Using Multiple Contexts} and @ref{Programmatic Help
2837 Strings}.
2838 @end defun
2841 @c -------------
2842 @c Extension API
2843 @c -------------
2844 @node Extension API, Versioning API, Runtime Phase API, API Quick Reference
2845 @section Extension API
2847 @defmac defoption CLASS SUPERCLASSES SLOTS &rest OPTIONS
2848 @pxref{New Option Classes}
2849 @end defmac
2851 @deffn {Generic Function} check OPTION VALUE
2852 @gfsubindex{check}
2853 @xref{Value Check Protocol}.
2854 @end deffn
2856 @deftp {Error Condition} option-error OPTION
2857 @ecsubindex{option-error}
2858 @ecsindex{option-error,option}
2859 @deftpx {Error Condition} invalid-value VALUE COMMENT
2860 @ecsubindex{invalid-value}
2861 @ecsindex{invalid-value,value}
2862 @ecsindex{invalid-value,comment}
2863 @xref{Value Check Protocol}.
2864 @end deftp
2866 @deffn {Generic Function} convert OPTION ARGUMENT
2867 @gfsubindex{convert}
2868 @xref{Argument Conversion Protocol}.
2869 @end deffn
2871 @deftp {Error Condition} invalid-argument ARGUMENT COMMENT
2872 @ecsubindex{invalid-argument}
2873 @ecsindex{invalid-argument,argument}
2874 @ecsindex{invalid-argument,comment}
2875 @xref{Argument Conversion Protocol}.
2876 @end deftp
2878 @deffn {Generic Function} stringify OPTION VALUE
2879 @gfsubindex{stringify}
2880 @xref{Value Stringification Protocol}.
2881 @end deffn
2884 @c --------------
2885 @c Versioning API
2886 @c --------------
2887 @node Versioning API, , Extension API, API Quick Reference
2888 @section Versioning API
2890 @defun version &optional (TYPE :number)
2891 @xref{Version Numbering}.
2892 @end defun
2894 @defvr Constant +release-major-level+
2895 @defvrx Constant +release-minor-level+
2896 @defvrx Constant +release-status+
2897 @defvrx Constant +release-status-level+
2898 @defvrx Constant +release-name+
2899 @xref{Version Numbering}.
2900 @end defvr
2904 @c ====================================================================
2905 @c Indexes
2906 @c ====================================================================
2907 @node Indexes, , API Quick Reference, Top
2908 @appendix Indexes
2910 @menu
2911 * Concept Index::       Well, the concept index
2912 * Function Index::      Well, the function index
2913 * Variable Index::      Well, the variable index
2914 * Data Type Index::     Well, the data type index
2915 @end menu
2918 @c --------------
2919 @c Concept Index
2920 @c --------------
2921 @node Concept Index, Function Index, Indexes, Indexes
2922 @section Concepts
2923 @printindex cp
2924 @page
2927 @c --------------
2928 @c Function Index
2929 @c --------------
2930 @node Function Index, Variable Index, Concept Index, Indexes
2931 @section Functions
2932 @printindex fn
2933 @page
2936 @c --------------
2937 @c Variable Index
2938 @c --------------
2939 @node Variable Index, Data Type Index, Function Index, Indexes
2940 @section Variables
2941 @printindex vr
2942 @page
2945 @c ---------------
2946 @c Data Type Index
2947 @c ---------------
2948 @node Data Type Index, , Variable Index, Indexes
2949 @section Data Types
2950 @printindex tp
2953 @bye
2955 @c  LocalWords:  Clon clon cmdline Clonification tty emph CmdLine clonified SGR
2956 @c  LocalWords:  clonfiscated clonistified clonificated clonificationated samp
2957 @c  LocalWords:  cindex subsubsection pxref Didier Nuker postfix Runtime cth
2958 @c  LocalWords:  cartouche toplevel prepended IEC
2960 @c user.texi ends here