5.14 match
(match expr [pattern expr] ...) |
A match form contains one or more “lines” that are
surrounded by parentheses or square brackets. Each line contains a
pattern— a description of a value— and an answer expr.
The initial expr is evaluated, and the resulting value
is matched against the pattern in each line, where the lines are
considered in order. The first line that contains a matching pattern
provides an answer expr whose value is the result of the
whole match expression. This expr may reference
identifiers bound in the matching pattern. If none of the lines
contains a matching pattern, it is an error.