The match form supports pattern matching on arbitrary Scheme values, as opposed to functions like regexp-match that compare regular expressions to byte and character sequences (see Regular Expressions).
(match target-expr [pattern expr ] )
The match form takes the result of target-expr and tries to match each pattern in order. As soon as it finds a match, it evaluates the corresponding expr sequence to obtain the result for the match form. If pattern includes pattern variables, they are treated like wildcards, and each variable is bound in the expr to the input fragments that it matched.
Most Scheme literal expressions can be used as patterns:
The struct construct matches an instance of a particular structure type:
|> (define-struct shoe (size color))|
|> (define-struct hat (size style))|
Unquoted, non-constructor identifiers in an pattern are pattern variables that are bound in the result expressions:
An ellipsis, written ..., act like a Kleene star within a list or vector pattern: the preceding sub-pattern can be used to match any number of times for any number of consecutive elements of the list of vector. If a sub-pattern followed by an ellipsis includes a pattern variable, the variable matches multiple times, and it is bound in the result expression to a list of matches:
Ellipses can be nested to match nested repetitions, and in that case, pattern variables can be bound to lists of lists of matches:
((1) (2 2) (3 3 3))
For information on many more pattern forms, see scheme/match.
(3 2 1)
For information on these additional forms, see scheme/match.