On this page:
redex-match
match?
match-bindings
bind
set-cache-size!
Version: 4.1

1 Patterns

 (require redex/reduction-semantics)

All of the exports in this section are provided both by redex/reduction-semantics (which includes all non-GUI portions of Redex) and also exported by redex (which includes all of Redex).

This section covers Redex’s pattern language, used in various ways:

  pattern

 

=

 

any

 

 

|

 

number

 

 

|

 

string

 

 

|

 

variable

 

 

|

 

(variable-except symbol ...)

 

 

|

 

(variable-prefix symbol)

 

 

|

 

variable-not-otherwise-mentioned

 

 

|

 

hole

 

 

|

 

symbol

 

 

|

 

(name symbol pattern)

 

 

|

 

(in-hole pattern pattern)

 

 

|

 

(hide-hole pattern)

 

 

|

 

(side-condition pattern guard)

 

 

|

 

(cross symbol)

 

 

|

 

(pattern-sequence ...)

 

 

|

 

scheme-constant

 

 

 

 

 

  pattern-sequence

 

=

 

pattern

 

 

|

 

... ; literal ellipsis

 

 

|

 

..._id

(redex-match lang pattern any)

(redex-match lang pattern)

If redex-match receives three arguments, it matches the pattern (in the language) against its third argument. If it matches, this returns a list of match structures describing the matches. If it fails, it returns #f.

If redex-match receives only two arguments, it builds a procedure for efficiently testing if expressions match the pattern, using the language lang. The procedures accepts a single expression and if the expresion matches, it returns a list of match structures describing the matches. If the match fails, the procedure returns #f.

(match? val)  boolean?

  val : any/c

Determines if a value is a match structure.

(match-bindings m)  (listof bind?)

  m : match?

This returns a bindings structure (see below) that binds the pattern variables in this match.

(struct

 

bind

 

(name exp))

  name : symbol?

  exp : any?

Instances of this struct are returned by redex-match. Each bind associates a name with an s-expression from the language, or a list of such s-expressions, if the (name ...) clause is followed by an ellipsis. Nested ellipses produce nested lists.

(set-cache-size! size)  void?

  size : (or/c false/c positive-integer?)

Changes the cache size; a #f disables the cache entirely. The default size is 350.

The cache is per-pattern (ie, each pattern has a cache of size at most 350 (by default)) and is a simple table that maps expressions to how they matched the pattern. When the cache gets full, it is thrown away and a new cache is started.