4.1 Command-Line Parsing🔗ℹ
(command-line flag-clause ... args-clause)
|
|
flag-clause | | = | | :program expr | | | | | | :preamble expr | | | | | | :usage expr | | | | | | :args-in expr | | | | | | :init expr | | | | | | :multi flag-spec ... | | | | | | :once-each flag-spec ... | | | | | | :once-any flag-spec ... | | | | | | flag-spec | | = | | (accum-id flags id ... help-spec | accum-body ...+) |
| | | | | | (flags id ... help-spec | proc-body ...+) |
| | | | | | flags | | = | | string | | | | | | (string ...) | | | | | | help-spec | | = | | string | | | | | | (string-expr ...) | | | | | | args-clause | | = | | | | | | | | :args args-formals | proc-body ... |
|
|
One small difference is that :args-in is used to specify a
list of incoming arguments instead of #:argv for an incoming
vector of arguments. The default :args-in uses
(hash-ref (runtime-env) 'args '()). Another difference is the
addition of :preamble, which supplies a string to be
shown before a “usage” line, and :usage, which supplies a
usage-options string as an alternative to the one inferred from an
:args clause.
A more significant difference is that zuo does not
have mutable data structures, so an explicit accumulator must be
threaded through flag parsing. An :init clause provides the
initial accumulator value defaulting to (hash). Each
flag-spec either starts with an accum-id, which is
bound to the value accumulated so far, or its body produces a function
to receive the accumulated value; either way, the result of the body
or procedure is a new accumulated value. Finally, the body of an
args-clause must produce a function to receive the
accumulated value.
Changed in version 1.3: Added :preamble.