Did you also notice that after creating a context, there is actually never any explicit reference to it anymore? So again, where is the magick? In fact, there’s no magick at all involved here either.
Clon
has a global variable named *context*
which holds the
current context. When you create a context with make-context
, it
is automatically made current, unless you use the :make-current
initarg with a value of nil
.
The whole runtime phase API of Clon
uses a context implicitely. This
involves progname
, remainder
, cmdline-options-p
,
cmdline-p
, getopt
, getopt-cmdline
,
multiple-value-getopt-cmdline
, do-cmdline-options
and
help
. As a consequence, it is possible to use Clon
with
multiple contexts at the same time. There are in fact three ways to
achieve this.
*context*
. All subsequent calls to the runtime phase API
will hence use this other context.
Clon
also provides a macro which changes the current context for you.
Execute BODY with *context*
bound to CONTEXT.
:context
key instead. The whole runtime phase API of Clon
understands it. For the functions getopt
, getopt-cmdline
and help
, it’s just another key in addition to those we’ve
already seen. For the macros multiple-value-getopt-cmdline
and
do-cmdline-options
, the key must appear at the end of the first
(list) argument, like this:
(multiple-value-getopt-cmdline (option name value :context ctx) ...) (do-cmdline-options (option name value :context ctx) ...)