"Sequence[expr1, expr2,...]"
is a single Expression
for many.
__
...is shorthand for a PatternSequence.
__head
...is a shorthand
for a PatternTypeSequence
whose elements match head.
Pattern[ptrnForm][Sequence] or
__[ptrnForm]
...is a PatternFormSequence
whose elements match ptrnForm.
Suppose construct is a Sequence,
List, Set, or String, and
orderFunc compares paired elements in construct and returns True
or False depending on their order.
Then construct is sorted by orderFunc
by eliciting...
Sequence[orderFunc][construct].
The default SortFunction,
(assigned to Sequence[Function]),
is invoked by:
Sequence[][construct]
See English definition of "sequence".
(0) Sequence
...is a frequently used suffix or prefix modifier.
The most common form is...
Sequence[e1, e2,...]
...which is a lexical device that regards
a multiple Expression
as a single Sequence
When "Sequence[]"
is used as a prefix, as in...
(1) Sequence[][construct]
...it sorts "construct". See SequenceConstruct
below.
When Sequence
is used as a suffix, as in...
(2) headExpression[Sequence]
...it is interpreted as a Sequence
specified by headExpression, which can be an Expression of arbitrary
complexity.
See PatternSequence.
A sequence of Expressions
may be regarded as a single Expression by wrapping
it in a Sequence construction as
follows:
(3) Sequence[expr1,
expr2,...]
For example, Cast expects
two arguments.
Sequence makes
that possible with the following construction.
Cast[{v=i,...},
Sequence[expr1, expr2,...]]
When a procedure generates one or more results with the same
form, then the multiple-same-form-result should be a Sequence rather then a List or some other construct,
unless there is a compelling reason for the non-Sequence construct. The Sequence preserves element order,
allows the result to be handled uniformly, and merges into containing Sequences or Lists. A Sequence of one or more elements
transforms into whatever construct
is needed. The "one or more" standard is the recommended default
behavior.
Usually, any Sequence[...] in a containing List or Sequence is merged into its container.
Furthermore, if head is any possible Head, then the
following rule is enforced:
head[Sequence[e1, e2,...]] → head[e1, e2,...]
For example,
{0, Sequence[1,
2, 3, 4], 5, 6} → {0, 1, 2, 3, 4, 5,
6}
Similarly,
Sequence[0, Sequence[1, 2, 3, 4], 5, 6] → Sequence[0, 1, 2, 3, 4, 5, 6]
By contrast,
(4) Cast[{v=blah,...},
Sequence[step1, step2,...]]
...does not merge into...
(5) Cast[{v=blah,...},
step1, step2,...].
This fact is significant since the first expression
has an interpretation and the last does not. (4) does not merge into (5)
because Cast has the Pattern Attribute. Similarly,
if Slot did not have
the Pattern Attribute, SlotSpecifications
would lose their definition when "Sequence[i1, i2]"
subExpressions
merge into their containing List or Sequence.
Generally, "Sequence[...]"
subExpressions
merge into their containing Lists or Sequences unless the Sequence is part of an
elicitation with the
Pattern Attribute.
NOTE: The following ElicitationForms
have their formal elicitations followed by a shorthand version which depends
upon ParaPuncs
and Operators
defined with the Standard ASCII
RuleList. As such, the shorthand versions are handy lexical
devices and not-necessary features of this Language
Specification.
(6) Pattern[Sequence]
...also written as...
__
...matches any Sequence of Expressions.
(7) Pattern[Type[head]][Sequence]
...also written as...
__head
or
...matches any Sequence of Expressions with Head matching
head.
(8) Pattern[ptrnBody][Sequence]
...also written as
__[ptrnBody]
...matches any Sequence
of Expressions matching
the PatternForm,
ptrnBody.
(10) Sequence[Function]
...is assigned to a Boolean Function that takes two
arguments and returns True if the
arguments are in "order", and
False otherwise. This default
"order" is based on numeric,
DataType, or alphabetic
order. Where an ordered element involves Characters, such
as in Name or a String, the default
"order" discriminates by CharacterSet.
If construct is a Sequence, List, Set, or String, then...
(11) Sequence[][construct]
...applies Sequence[Function], (the "default sort"), to construct returning the sorted result.
More generally, suppose
orderFunc is any Function that compares element
pairs in construct, and returns
True or False depending on their sort-order. Then...
(12) Sequence[orderFunc][construct]
...returns the resorted construct.
Note that if the default sort, "Sequence[Function]", is substituted for orderFunc
in (11), the resulting expression...
Sequence[Sequence[Function]][construct]
...is equivalent to (11).
For (11) and (12):
1. State of fact of being sequent; a following or coming after or in succession.
The inevitable sequences of sin
and punishment. Bp. Hall.
2. A series having continuity and connection, and often uniformity, as of reflections, chambers.
Learning how words sound in sequence.
F. Wilkenson
3. That which follows later or as a consequence; result; sequel; as, the natural sequence to folly.
4. The quality of having orderly, esp. logical, connectedness of successive events or parts; specif., consecutiveness in a work of literature or art; as, a sense for sequence show in arranging narrative.
5. The order in which events are connected or related in time; simple succession; esp., the connection of antecedent and consequent in a temporal series, apart from any causal necessity; as, the reactions of chemical agents may be conceived as merely invariable sequences.
6. An extended series of poems, usually sonnets, united by a single theme.
7. Card playing. Three or more cards of the same suit in immediately consecutive order of value, as knave, ten, nine, and eight.
8. Logic & Math. Any one-dimensional order of elements or terms; also, the elements or terms in their order; esp., the order of a discrete series. Abbr. Sq.
9. Math. A denumerable succession (determined by law) of elements, a1, a2, ... an,..., between which and the natural numbers, 1, 2, ..., n,..., a one-to-one correspondence has been established.
10. Music. A succession of repeated harmonic or melodic phrases rising or falling usually by regular diatonic degrees in the same scale. Cf. RASALIA. An exact or chromatic sequence is repeated precisely, interval for interval; a diatonic sequence uses only the tones of the key.
1. Obs. a A follower.
b One of a sequence.
c That which ensues in a series of events.
2. That which follows in a regular order, series, or the like.
3. That which follows as a result; a sequence or sequel.
[Definitions
from Websters1949Unabridged.]
(c) 2004-2007 by
John Van Wie Bergamini.
All rights reserved.