Skip to content

The (ice-9 getopt-long) Module

The (ice-9 getopt-long) facility is designed to help parse arguments that are passed to Guile programs on the command line, and is modelled after the C library’s facility of the same name (see Getopt in The GNU C Library Reference Manual). For a more low-level interface to command-line argument parsing, See SRFI-37 - args-fold.

The (ice-9 getopt-long) module exports two procedures: getopt-long and option-ref.

  • getopt-long takes a list of strings — the command line arguments — an option specification, and some optional keyword parameters. It parses the command line arguments according to the option specification and keyword parameters, and returns a data structure that encapsulates the results of the parsing.
  • option-ref then takes the parsed data structure and a specific option’s name, and returns information about that option in particular.

To make these procedures available to your Guile script, include the expression (use-modules (ice-9 getopt-long)) somewhere near the top, before the first usage of getopt-long or option-ref.