Pattern R

pattern.spad line 1 [edit on github]

Patterns for use by the pattern matcher.

0: %

0

1: %

1

*: (%, %) -> %

a * b returns the pattern a * b.

+: (%, %) -> %

a + b returns the pattern a + b.

/: (%, %) -> %

a / b returns the pattern a / b.

=: (%, %) -> Boolean

from BasicType

^: (%, %) -> %

a ^ b returns the pattern a ^ b.

^: (%, NonNegativeInteger) -> %

a ^ n returns the pattern a ^ n.

~=: (%, %) -> Boolean

from BasicType

addBadValue: (%, Any) -> %

addBadValue(p, v) adds v to the list of “bad values” for p. 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 if p contains no matching variables.

convert: List % -> %

convert([a1, ..., an]) returns the pattern [a1, ..., an].

copy: % -> %

copy(p) returns a recursive copy of p.

depth: % -> NonNegativeInteger

depth(p) returns the nesting level of p.

elt: (BasicOperator, List %) -> %

elt(op, [a1, ..., an]) returns op(a1, ..., an).

generic?: % -> Boolean

generic?(p) tests if p is a single matching variable.

getBadValues: % -> List Any

getBadValues(p) returns the list of “bad values” for p. Note: p is not allowed to match any of its “bad values”.

hash: % -> SingleInteger

from SetCategory

hashUpdate!: (HashState, %) -> HashState

from SetCategory

hasPredicate?: % -> Boolean

hasPredicate?(p) tests if p has predicates attached to it.

hasTopPredicate?: % -> Boolean

hasTopPredicate?(p) tests if p has a top-level predicate.

inR?: % -> Boolean

inR?(p) tests if p is an atom (i.e. an element of R).

isExpt: % -> Union(Record(val: %, exponent: NonNegativeInteger), failed)

isExpt(p) returns [q, n] if n > 0 and p = q ^ n, and “failed” otherwise.

isList: % -> Union(List %, failed)

isList(p) returns [a1, ..., an] if p = [a1, ..., an], “failed” otherwise.

isOp: % -> Union(Record(op: BasicOperator, arg: List %), failed)

isOp(p) returns [op, [a1, ..., an]] if p = op(a1, ..., an), and “failed” otherwise.

isOp: (%, BasicOperator) -> Union(List %, failed)

isOp(p, op) returns [a1, ..., an] if p = op(a1, ..., an), and “failed” otherwise.

isPlus: % -> Union(List %, failed)

isPlus(p) returns [a1, ..., an] if n > 1 and p = a1 + ... + an, and “failed” otherwise.

isPower: % -> Union(Record(val: %, exponent: %), failed)

isPower(p) returns [a, b] if p = a ^ b, and “failed” otherwise.

isQuotient: % -> Union(Record(num: %, den: %), failed)

isQuotient(p) returns [a, b] if p = a / b, and “failed” otherwise.

isTimes: % -> Union(List %, failed)

isTimes(p) returns [a1, ..., an] if n > 1 and p = a1 * ... * an, and “failed” otherwise.

latex: % -> String

from SetCategory

multiple?: % -> Boolean

multiple?(p) tests if p is a single matching variable allowing list matching or multiple term matching in a sum or product.

optional?: % -> Boolean

optional?(p) tests if p is a single matching variable which can match an identity.

optpair: List % -> Union(List %, failed)

optpair(l) returns l 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 variable x, which is constant if c? = true, optional if o? = true, and multiple if m? = true.

predicates: % -> List Any

predicates(p) returns [p1, ..., pn] such that the predicate attached to p is p1 and … and pn.

quoted?: % -> Boolean

quoted?(p) tests if p is of the form 's for a symbol s.

resetBadValues: % -> %

resetBadValues(p) initializes the list of “bad values” for p 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 predicate p1 and … and pn to p.

setTopPredicate: (%, List Symbol, Any) -> %

setTopPredicate(x, [a1, ..., an], f) returns x with the top-level predicate set to f(a1, ..., an).

symbol?: % -> Boolean

symbol?(p) tests if p is a symbol.

topPredicate: % -> Record(var: List Symbol, pred: Any)

topPredicate(x) returns [[a1, ..., an], f] where the top-level predicate of x is f(a1, ..., an). Note: n is 0 if x has no top-level predicate.

variables: % -> List %

variables(p) returns the list of matching variables appearing in p.

withPredicates: (%, List Any) -> %

withPredicates(p, [p1, ..., pn]) makes a copy of p and attaches the predicate p1 and … and pn to the copy, which is returned.

BasicType

CoercibleFrom R

CoercibleFrom Symbol

CoercibleTo OutputForm

RetractableTo R

RetractableTo Symbol

SetCategory