For Development HEAD DRAFTSearch (procedure/syntax/module):

Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]

11.64 srfi.239 - Destructuring lists

Module: srfi.239

This module provides a pattarn-matching macro specialized for the common pattern appearing frequently in list processing code. It can be seen as a subset of match (see util.match - Pattern matching); if you’re writing Gauche-specific code, you don’t need this module. However, this is useful for portable code.

Macro: list-case expr clause …

[SRFI-239]{srfi.239} Each clause must be one of the following forms:

  • ((var1 . var2) body …)
  • (() body …)
  • (var body …)

Here, var, var1, var2 are identifiers. The order of clauses does not matter, and not all three forms need to be present.

First expr is evaluated. If it is a pair, the first type of clause is selected, and body … are evaluated with the environment where the pair’s car is bound to var1 and the pair’s cdr is bound to var2. If it is an empty list, the second type of clause is selected, and its body … are evaluated. Otherwise, the third type of clause is selected, its body … are evaluated where the value of expr is bound to var.

The identifier _ has special meaning in var, var1, and var2; it is not bound and the corresponding value is simply discarded.

If not all three forms are present and the result of expr does not match the provided clauses, an error is thrown. Note that, unlike match, if the first type of clause isn’t provided, a pair does not match the third type of clause


Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]


For Development HEAD DRAFTSearch (procedure/syntax/module):
DRAFT