Pattern R¶
pattern.spad line 1 [edit on github]
R: SetCategory
Patterns for use by the pattern matcher.
- 0: %
0
- 1: %
1
- *: (%, %) -> %
a * b
returns the patterna * b
.
- +: (%, %) -> %
a + b
returns the patterna + b
.
- /: (%, %) -> %
a / b
returns the patterna / b
.
- ^: (%, %) -> %
a ^ b
returns the patterna ^ b
.
- ^: (%, NonNegativeInteger) -> %
a ^ n
returns the patterna ^ n
.
- addBadValue: (%, Any) -> %
addBadValue(p, v)
addsv
to the list of “bad values” forp
. Note:p
is not allowed to match any of its “bad values”.
- coerce: % -> OutputForm
from CoercibleTo OutputForm
- coerce: R -> %
from CoercibleFrom R
- coerce: Symbol -> %
from CoercibleFrom Symbol
- constant?: % -> Boolean
constant?(p)
tests ifp
contains no matching variables.
- convert: List % -> %
convert([a1, ..., an])
returns the pattern[a1, ..., an]
.
- copy: % -> %
copy(p)
returns a recursive copy ofp
.
- depth: % -> NonNegativeInteger
depth(p)
returns the nesting level ofp
.
- elt: (BasicOperator, List %) -> %
elt(op, [a1, ..., an])
returnsop(a1, ..., an)
.
- generic?: % -> Boolean
generic?(p)
tests ifp
is a single matching variable.
- getBadValues: % -> List Any
getBadValues(p)
returns the list of “bad values” forp
. Note:p
is not allowed to match any of its “bad values”.
- hasPredicate?: % -> Boolean
hasPredicate?(p)
tests ifp
has predicates attached to it.
- hasTopPredicate?: % -> Boolean
hasTopPredicate?(p)
tests ifp
has a top-level predicate.
- inR?: % -> Boolean
inR?(p)
tests ifp
is an atom (i.e. an element ofR
).
- isExpt: % -> Union(Record(val: %, exponent: NonNegativeInteger), failed)
isExpt(p)
returns[q, n]
ifn > 0
andp = q ^ n
, and “failed” otherwise.
- isList: % -> Union(List %, failed)
isList(p)
returns[a1, ..., an]
ifp = [a1, ..., an]
, “failed” otherwise.
- isOp: % -> Union(Record(op: BasicOperator, arg: List %), failed)
isOp(p)
returns[op, [a1, ..., an]]
ifp = op(a1, ..., an)
, and “failed” otherwise.
- isOp: (%, BasicOperator) -> Union(List %, failed)
isOp(p, op)
returns[a1, ..., an]
ifp = op(a1, ..., an)
, and “failed” otherwise.
- isPlus: % -> Union(List %, failed)
isPlus(p)
returns[a1, ..., an]
ifn > 1
andp = a1 + ... + an
, and “failed” otherwise.
- isPower: % -> Union(Record(val: %, exponent: %), failed)
isPower(p)
returns[a, b]
ifp = a ^ b
, and “failed” otherwise.
- isQuotient: % -> Union(Record(num: %, den: %), failed)
isQuotient(p)
returns[a, b]
ifp = a / b
, and “failed” otherwise.
- isTimes: % -> Union(List %, failed)
isTimes(p)
returns[a1, ..., an]
ifn > 1
andp = a1 * ... * an
, and “failed” otherwise.
- latex: % -> String
from SetCategory
- multiple?: % -> Boolean
multiple?(p)
tests ifp
is a single matching variable allowing list matching or multiple term matching in a sum or product.
- optional?: % -> Boolean
optional?(p)
tests ifp
is a single matching variable which can match an identity.
- optpair: List % -> Union(List %, failed)
optpair(l)
returnsl
has the form[a, b]
and a is optional, and “failed” otherwise.
- patternVariable: (Symbol, Boolean, Boolean, Boolean) -> %
patternVariable(x, c?, o?, m?)
creates a pattern variablex
, which is constant ifc? = true
, optional ifo? = true
, and multiple ifm? = true
.
- predicates: % -> List Any
predicates(p)
returns[p1, ..., pn]
such that the predicate attached top
isp1
and … andpn
.
- quoted?: % -> Boolean
quoted?(p)
tests ifp
is of the form's
for a symbols
.
- resetBadValues: % -> %
resetBadValues(p)
initializes the list of “bad values” forp
to[]
. Note:p
is not allowed to match any of its “bad values”.
- retract: % -> R
from RetractableTo R
- retract: % -> Symbol
from RetractableTo Symbol
- retractIfCan: % -> Union(R, failed)
from RetractableTo R
- retractIfCan: % -> Union(Symbol, failed)
from RetractableTo Symbol
- setPredicates: (%, List Any) -> %
setPredicates(p, [p1, ..., pn])
attaches the predicatep1
and … andpn
top
.
- setTopPredicate: (%, List Symbol, Any) -> %
setTopPredicate(x, [a1, ..., an], f)
returnsx
with the top-level predicate set tof(a1, ..., an)
.
- symbol?: % -> Boolean
symbol?(p)
tests ifp
is a symbol.
- topPredicate: % -> Record(var: List Symbol, pred: Any)
topPredicate(x)
returns[[a1, ..., an], f]
where the top-level predicate ofx
isf(a1, ..., an)
. Note:n
is 0 ifx
has no top-level predicate.
- variables: % -> List %
variables(p)
returns the list of matching variables appearing inp
.