The pattern matcher offers the following primitives:
make-match&env
pat kwd-list
cpat
match-against
cpat read
env
( penv + #f)
pexpand
pat penv
kwd-list
mixed
make-match&env is used to pre-compile patterns. Typically, the computation that compiles patterns will be hoisted out of procedure bodies so that the compilation takes place once while its result can be used several times.
match-against performs the actual matching of a given
expression (of type read) against a compiled
pattern. If the expression matches the
pattern, a pattern environment, which is a non-false value, is
returned; else the result is #f.
pexpand expands patterns in the context of a pattern environment and a list of keywords. The first argument is recursively copied verbatim into the output unless an identifier is encountered that is bound in the pattern environment and is not in the keyword list; this identifier is replaced by its binding, which has type read, in the pattern environment, and transcription proceeds accordingly. The output of compositing pexpand with structurize-syntax yields an object of type read, which can be subjected to further pattern matching, etc.
match-and-rewrite
read cpat
pat
kwd-list
env
( mixed + #f)
match-and-rewrite is used to provide a concise means of writing rewrite rules. It is particularly useful for writing source-to-source transformations (macros). In Section 6.3, we will show the source for this procedure.