Next: srfi args-fold examples, Previous: srfi args-fold rationale, Up: srfi args-fold [Index]
args-fold
is an iterator similar to SRFI-1 fold procedure
(“the fundamental list iterator”). As it parses options and operands,
it calls their corresponding operand and option processors. Unlike
mapping, folding passes state, called seeds, from one processor to the
next.
For example, a program may need a list of operands and a table of
options. To build these, args-fold
could be seeded with an empty
operand list, and an empty option table. The operand processor could
add the operands to the operand list, and the option processors could
add the options to the option table. Along the way, some option
processors might even take immediate action for options like
--version
or --help
. This kind of heterogeneous
processing is appropriate for program arguments, and folding allows a
functional implementation if desired.
Prototype for an option–processor. It should return the next seeds as
values. option will be the option. name will be one of the
option’s option–names as encountered by args-fold
.
arg will be a string, or #f
if args-fold
didn’t
encounter an option–argument.
Prototype for an operand–processor. It should return the next seeds as values. operand will be a string.
Return an option. names is a list of short (character) and long
(string) option names. required-arg? specifies if this options
requires an option–argument (boolean). optional-arg? specifies
if this option can accept an option–argument (boolean).
option-proc is a procedure (following the option-processor
prototype) used to process this option.
Return the contents of corresponding fields of option.
Parse argument strings left–to–right, calling the appropriate processors in–order (for the parsed known options, unknown options, and operands), passing the seed values from one processor to the next and returning the final seeds values as results.
args is a list of strings. options is a list of options.
unrecognized-option-proc is a procedure (following the
option-processor
prototype) for unrecognized options.
operand-proc is a procedure (following the
operand-processor
prototype) for operands.
NOTE
args-fold
will create temporary options as necessary for theunrecognized-option-proc
.
Next: srfi args-fold examples, Previous: srfi args-fold rationale, Up: srfi args-fold [Index]