Pattern R¶
pattern.spad line 1 [edit on github]
R: SetCategory
Patterns for use by the pattern matcher.
- 0: %
0
- 1: %
1
- *: (%, %) -> %
a * breturns the patterna * b.
- +: (%, %) -> %
a + breturns the patterna + b.
- /: (%, %) -> %
a / breturns the patterna / b.
- ^: (%, %) -> %
a ^ breturns the patterna ^ b.
- ^: (%, NonNegativeInteger) -> %
a ^ nreturns the patterna ^ n.
- addBadValue: (%, Any) -> %
addBadValue(p, v)addsvto the list of “bad values” forp. Note:pis 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 ifpcontains 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 ifpis a single matching variable.
- getBadValues: % -> List Any
getBadValues(p)returns the list of “bad values” forp. Note:pis not allowed to match any of its “bad values”.
- hasPredicate?: % -> Boolean
hasPredicate?(p)tests ifphas predicates attached to it.
- hasTopPredicate?: % -> Boolean
hasTopPredicate?(p)tests ifphas a top-level predicate.
- inR?: % -> Boolean
inR?(p)tests ifpis an atom (i.e. an element ofR).
- isExpt: % -> Union(Record(val: %, exponent: NonNegativeInteger), failed)
isExpt(p)returns[q, n]ifn > 0andp = 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 > 1andp = 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 > 1andp = a1 * ... * an, and “failed” otherwise.
- latex: % -> String
from SetCategory
- multiple?: % -> Boolean
multiple?(p)tests ifpis a single matching variable allowing list matching or multiple term matching in a sum or product.
- optional?: % -> Boolean
optional?(p)tests ifpis a single matching variable which can match an identity.
- optpair: List % -> Union(List %, failed)
optpair(l)returnslhas 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 topisp1and … andpn.
- quoted?: % -> Boolean
quoted?(p)tests ifpis of the form'sfor a symbols.
- resetBadValues: % -> %
resetBadValues(p)initializes the list of “bad values” forpto[]. Note:pis 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 predicatep1and … andpntop.
- setTopPredicate: (%, List Symbol, Any) -> %
setTopPredicate(x, [a1, ..., an], f)returnsxwith the top-level predicate set tof(a1, ..., an).
- symbol?: % -> Boolean
symbol?(p)tests ifpis a symbol.
- topPredicate: % -> Record(var: List Symbol, pred: Any)
topPredicate(x)returns[[a1, ..., an], f]where the top-level predicate ofxisf(a1, ..., an). Note:nis 0 ifxhas no top-level predicate.
- variables: % -> List %
variables(p)returns the list of matching variables appearing inp.