PatternMatchResult(R, S)¶
patmatch1.spad line 1 [edit on github]
R: SetCategory
S: SetCategory
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: (Pattern R, S, %) -> %
addMatch(var, expr, r)
adds the match (var
,expr
) inr
, provided thatexpr
satisfies the predicates attached tovar
, and thatvar
is not matched to another expression already.
- addMatchRestricted: (Pattern R, S, %, S) -> %
addMatchRestricted(var, expr, r, val)
adds the match (var
,expr
) inr
, provided thatexpr
satisfies the predicates attached tovar
, thatvar
is not matched to another expression already, and that eithervar
is an optional pattern variable or thatexpr
is not equal to val (usually an identity).
- coerce: % -> OutputForm
from CoercibleTo OutputForm
- construct: List Record(key: Symbol, entry: S) -> %
construct([v1, e1], ..., [vn, en])
returns the match result containing the matches (v1
,e1
), …, (vn
, en).
- destruct: % -> List Record(key: Symbol, entry: S)
destruct(r)
returns the list of matches (var, expr) inr
. Error: ifr
is a failed match.
- failed?: % -> Boolean
failed?(r)
tests ifr
is a failed match.
- failed: () -> %
failed()
returns a failed match.
- getMatch: (Pattern R, %) -> Union(S, failed)
getMatch(var, r)
returns the expression thatvar
matches in the resultr
, and “failed” ifvar
is not matched inr
.
- insertMatch: (Pattern R, S, %) -> %
insertMatch(var, expr, r)
adds the match (var
,expr
) inr
, without checking predicates or previous matches forvar
.
- latex: % -> String
from SetCategory
- new: () -> %
new()
returns a new empty match result.
- satisfy?: (%, Pattern R) -> Union(Boolean, failed)
satisfy?(r, p)
returnstrue
if the matches satisfy the top-level predicate ofp
,false
if they don't
, and “failed” if not enough variables ofp
are matched inr
to decide.
- union: (%, %) -> %
union(a, b)
makes the set-union of two match results.