patmatch1.spad line 1 [edit on github]
A PatternMatchResult is an object internally returned by the pattern matcher; It is either a failed match, or a list of matches of the form (var, expr) meaning that the variable var matches the expression expr.
addMatch(var, expr, r)
adds the match (var
, expr
) in r
, provided that expr
satisfies the predicates attached to var
, and that var
is not matched to another expression already.
addMatchRestricted(var, expr, r, val)
adds the match (var
, expr
) in r
, provided that expr
satisfies the predicates attached to var
, that var
is not matched to another expression already, and that either var
is an optional pattern variable or that expr
is not equal to val (usually an identity).
construct([v1, e1], ..., [vn, en])
returns the match result containing the matches (v1
, e1
), ..., (vn
, en).
destruct(r)
returns the list of matches (var, expr) in r
. Error: if r
is a failed match.
failed()
returns a failed match.
failed?(r)
tests if r
is a failed match.
getMatch(var, r)
returns the expression that var
matches in the result r
, and "failed" if var
is not matched in r
.
insertMatch(var, expr, r)
adds the match (var
, expr
) in r
, without checking predicates or previous matches for var
.
new()
returns a new empty match result.
satisfy?(r, p)
returns true
if the matches satisfy the top-level predicate of p
, false
if they don't
, and "failed" if not enough variables of p
are matched in r
to decide.
union(a, b)
makes the set-union of two match results.