Next: , Previous: , Up: srfi args-fold   [Index]


2.20.4 Specification

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.

Procedure Prototype: option-processor option name arg seeds ...

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.

Procedure Prototype: operand-processor operand seeds

Prototype for an operand–processor. It should return the next seeds as values. operand will be a string.

Function: option names required-arg? optional-arg? option-proc

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.

Function: option-names option
Function: option-required-arg? option
Function: option-optional-arg? option
Function: option-processor option

Return the contents of corresponding fields of option.

Function: args-fold args options unrecognized-option-proc operand-proc seeds ...

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 the unrecognized-option-proc.


Next: , Previous: , Up: srfi args-fold   [Index]