[previous] [up] [next]     [contents] [index]
Next: Patterns Up: Introduction Previous: Types

Primitives

The pattern matcher offers the following primitives:

tex2html_wrap_inline1697 make-match&env
pat tex2html_wrap_inline1701 kwd-list tex2html_wrap_inline1699 cpat
tex2html_wrap_inline1697 match-against
cpat tex2html_wrap_inline1701 read tex2html_wrap_inline1701 env tex2html_wrap_inline1699 ( penv + #f)
tex2html_wrap_inline1697 pexpand
pat tex2html_wrap_inline1701 penv tex2html_wrap_inline1701 kwd-list tex2html_wrap_inline1699 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[footnote]. 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.

tex2html_wrap_inline1697 match-and-rewrite
read tex2html_wrap_inline1701 cpat tex2html_wrap_inline1701 pat tex2html_wrap_inline1701 kwd-list tex2html_wrap_inline1701 env tex2html_wrap_inline1699 ( 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.



PLT