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


2.20.3 Rationale

Program arguments are the primary interface to many programs, so processing arguments is a common programming task. There are many common (often conflicting) ways take care of this task, so a custom processor is often necessary; however, many programmers (and their users) would welcome a convenient interface supporting common guidelines.

POSIX provides several guidelines for the specification of program options, option–arguments, and operands. It also notes historical exceptions to these guidelines. The GNU C Library Reference Manual describes long option extensions to the POSIX guidelines.

This SRFI supports creating programs following the guidelines mentioned above by:

It parses argument strings according to the following rules:

  1. each short–option name is a single character;
  2. one or more short–options are accepted in a single argument string when grouped behind one - delimiter character; examples: -a, -bcd;
  3. a short–option–argument is accepted in a separate argument string immediately following a short–option; examples: -a foo, -bcd bar;
  4. also (for historical reasons) a short–option–argument is accepted immediately following the last short–option in a single argument string; examples: -afoo, -bcdbar;
  5. each long–option name is one or more characters;
  6. one long–option is accepted in a single argument string when preceded by two - delimiter characters; example: --help;
  7. in a single argument string, a long–option followed by one = delimiter character followed by a long–option–argument is accepted; example: --speed=fast;
  8. the first -- argument string is accepted as a delimiter indicating the end of options; it is not treated as an option or an operand; any argument strings following this delimiter are treated as operands, even if they begin with the - character;
  9. all other argument strings are treated as operands; this includes argument strings consisting of a single - character;
  10. operands may be intermingled with options in any order.

Preliminary versions of this interface are already available for some Scheme implementations: here for Chicken, and here for Scsh.


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