UnaryRecursiveAggregate S¶
aggcat.spad line 1296 [edit on github]
S: Type
A unary-recursive aggregate is an aggregate where nodes may have either 0 or 1 children. This aggregate models, though not precisely, a linked list possibly with a single cycle. A node with one children models a non-empty list, with the value of the list designating the head, or first, of the list, and the child designating the tail, or rest, of the list. Since these aggregates are recursive aggregates, they may be cyclic.
- #: % -> NonNegativeInteger if % has finiteAggregate
from Aggregate
- =: (%, %) -> Boolean if S has SetCategory or S has BasicType and % has finiteAggregate
from BasicType
- ~=: (%, %) -> Boolean if S has SetCategory or S has BasicType and % has finiteAggregate
from BasicType
- any?: (S -> Boolean, %) -> Boolean if % has finiteAggregate
from HomogeneousAggregate S
- child?: (%, %) -> Boolean if S has BasicType
from RecursiveAggregate S
- children: % -> List %
from RecursiveAggregate S
- coerce: % -> OutputForm if S has CoercibleTo OutputForm
from CoercibleTo OutputForm
- concat!: (%, %) -> % if % has shallowlyMutable
concat!(u, v)
destructively concatenatesv
to the end ofu
.
- concat!: (%, S) -> % if % has shallowlyMutable
concat!(u, x)
destructively adds elementx
to the end ofu
. Note:concat!(a, x) = concat!(a, [x])
.
- concat!: List % -> % if % has shallowlyMutable
concat!(lu)
, wherelu
is a list of aggregates[a, b, ..., c]
, returns a single aggregate consisting of the elements ofa
followed by those ofb
followed … by the elements ofc
. This function may destructively modify the aggregates inlu
.
- concat: (%, %) -> %
concat(u, v)
returns an aggregatew
consisting of the elements ofu
followed by the elements ofv
. Note:v = rest(w, \#u)
.
- concat: (S, %) -> %
concat(x, u)
returns aggregate consisting ofx
followed by the elements ofu
. Note: ifv = concat(x, u)
thenx = first v
andu = rest v
.
- count: (S -> Boolean, %) -> NonNegativeInteger if % has finiteAggregate
from HomogeneousAggregate S
- count: (S, %) -> NonNegativeInteger if S has BasicType and % has finiteAggregate
from HomogeneousAggregate S
- cycleEntry: % -> %
cycleEntry(u)
returns the head of a top-level cycle contained in aggregateu
, orempty()
if none exists.
- cycleLength: % -> NonNegativeInteger
cycleLength(u)
returns the length of a top-level cycle contained in aggregateu
, or 0 ifu
has no such cycle.
- cycleSplit!: % -> % if % has shallowlyMutable
cycleSplit!(u)
splits the aggregate by dropping off the cycle. The value returned is the cycle entry, or empty() if none exists. For example, ifw = concat(u, v)
is the cyclic list wherev
is the head of the cycle,cycleSplit!(w)
will dropv
offw
thus destructively changingw
tou
, and returningv
.
- cycleTail: % -> %
cycleTail(u)
returns the last node in the cycle, or empty() if none exists.
- cyclic?: % -> Boolean
from RecursiveAggregate S
- distance: (%, %) -> Integer
from RecursiveAggregate S
- elt: (%, first) -> S
elt(u, "first")
(also written:u.first
) is equivalent to first(u
).
- elt: (%, last) -> S
elt(u, "last")
(also written:u.last
) is equivalent to last(u
).
- elt: (%, rest) -> %
elt(\%, "rest")
(also written:u.rest
) is equivalent torest u
.- elt: (%, value) -> S
from RecursiveAggregate S
- eval: (%, Equation S) -> % if S has Evalable S and S has SetCategory
from Evalable S
- eval: (%, List Equation S) -> % if S has Evalable S and S has SetCategory
from Evalable S
- eval: (%, List S, List S) -> % if S has Evalable S and S has SetCategory
from InnerEvalable(S, S)
- eval: (%, S, S) -> % if S has Evalable S and S has SetCategory
from InnerEvalable(S, S)
- every?: (S -> Boolean, %) -> Boolean if % has finiteAggregate
from HomogeneousAggregate S
- first: % -> S
first(u)
returns the first element ofu
(equivalently, the value at the current node).
- first: (%, NonNegativeInteger) -> %
first(u, n)
returns a copy of the firstn
elements ofu
.
- last: % -> S
last(u)
returns the last element ofu
. Note: for lists,last(u) = u.(maxIndex u)
.
- last: (%, NonNegativeInteger) -> %
last(u, n)
returns a copy of the lastn
nodes ofu
. Note:last(u, n)
is a list ofn
elements.
- latex: % -> String if S has SetCategory
from SetCategory
- leaf?: % -> Boolean
from RecursiveAggregate S
- leaves: % -> List S
from RecursiveAggregate S
- less?: (%, NonNegativeInteger) -> Boolean
from Aggregate
- map!: (S -> S, %) -> % if % has shallowlyMutable
from HomogeneousAggregate S
- map: (S -> S, %) -> %
from HomogeneousAggregate S
- max: % -> S if S has OrderedSet and % has finiteAggregate
from HomogeneousAggregate S
- max: ((S, S) -> Boolean, %) -> S if % has finiteAggregate
from HomogeneousAggregate S
- member?: (S, %) -> Boolean if S has BasicType and % has finiteAggregate
from HomogeneousAggregate S
- members: % -> List S if % has finiteAggregate
from HomogeneousAggregate S
- min: % -> S if S has OrderedSet and % has finiteAggregate
from HomogeneousAggregate S
- more?: (%, NonNegativeInteger) -> Boolean
from Aggregate
- node?: (%, %) -> Boolean if S has BasicType
from RecursiveAggregate S
- nodes: % -> List %
from RecursiveAggregate S
- parts: % -> List S if % has finiteAggregate
from HomogeneousAggregate S
- qsetfirst!: (%, S) -> S if % has shallowlyMutable
qsetfirst!(u, x)
destructively changes the first element ofu
tox
without checking for errors.
- qsetrest!: (%, %) -> % if % has shallowlyMutable
qsetrest!(u, v)
destructively changes the rest ofu
tov
without checking for errors.
- rest: % -> %
rest(u)
returns an aggregate consisting of all but the first element ofu
(equivalently, the next node ofu
).
- rest: (%, NonNegativeInteger) -> %
rest(u, n)
returns then
th node ofu
. Note:rest(u, 0) = u
.
- second: % -> S
second(u)
returns the second element ofu
. Note:second(u) = first(rest(u))
.
- setchildren!: (%, List %) -> % if % has shallowlyMutable
from RecursiveAggregate S
- setelt!: (%, first, S) -> S if % has shallowlyMutable
setelt!(u, "first", x)
(also written:u.first := x
) is equivalent tosetfirst!(u, x)
.
- setelt!: (%, last, S) -> S if % has shallowlyMutable
setelt!(u, "last", x)
(also written:u.last := x
) is equivalent tosetlast!(u, x)
.
- setelt!: (%, rest, %) -> % if % has shallowlyMutable
setelt!(u, "rest", v)
(also written:u.rest := v
) is equivalent tosetrest!(u, v)
.- setelt!: (%, value, S) -> S if % has shallowlyMutable
from RecursiveAggregate S
- setfirst!: (%, S) -> S if % has shallowlyMutable
setfirst!(u, x)
destructively changes the first element ofu
tox
. Error ifu
is empty.
- setlast!: (%, S) -> S if % has shallowlyMutable
setlast!(u, x)
destructively changes the last element ofu
tox
. Error ifu
is empty.
- setrest!: (%, %) -> % if % has shallowlyMutable
setrest!(u, v)
destructively changes the rest ofu
tov
. Error ifu
is empty.
- setvalue!: (%, S) -> S if % has shallowlyMutable
from RecursiveAggregate S
- size?: (%, NonNegativeInteger) -> Boolean
from Aggregate
- split!: (%, NonNegativeInteger) -> % if % has shallowlyMutable
split!(u, n)
splitsu
into two aggregates:v = rest(u, n)
andw = first(u, n)
, returningv
and settingu
tow
. Ifn
is 0, split! currently only works for Stream and gives error for List. Note: afterwardsrest(u, n)
returnsempty()
.
- tail: % -> %
tail(u)
returns the last node ofu
. Error ifu
is empty.
- third: % -> S
third(u)
returns the third element ofu
. Note:third(u) = first(rest(rest(u)))
.
- value: % -> S
from RecursiveAggregate S
BasicType if S has SetCategory or S has BasicType and % has finiteAggregate
CoercibleTo OutputForm if S has CoercibleTo OutputForm
Evalable S if S has Evalable S and S has SetCategory
InnerEvalable(S, S) if S has Evalable S and S has SetCategory
SetCategory if S has SetCategory