--- layout: default title: "Sequences" parent: Composite ancestor: Funcons-beta --- [Funcons-beta] : [Sequences.cbs] ----------------------------- ### Sequences of values
[
Funcon length
Funcon index
Funcon is-in
Funcon first
Funcon second
Funcon third
Funcon first-n
Funcon drop-first-n
Funcon reverse
Funcon n-of
Funcon intersperse
]X1, ..., Xn is written X1,...,Xn.
A sequence with a single element X is identified with (and written) X.
An empty sequence is indicated by the absence of a term.
Any sequence X* can be enclosed in parentheses (X*), e.g.:
( ), (1), (1,2,3). Superfluous commas are ignored.
The elements of a type sequence T1,...,Tn are the value sequences V1,...,Vn
where V1:T1, ..., Vn:Tn. The only element of the empty type sequence ( )
is the empty value sequence ( ).
(T)^N is equivalent to T,...,T with N occurrences of T.
(T)* is equivalent to the union of all (T)^N for N>=0,
(T)+ is equivalent to the union of all (T)^N for N>=1, and
(T)? is equivalent to T | ( ).
The parentheses around T above can be omitted when they are not needed for
disambiguation.
(Non-trivial) sequence types are not values, so not included in types.
Meta-variables
T, T′ <: valuesFuncon
length(_:values*) : =>natural-numberslength(V*) gives the number of elements in V*.
Funcon
is-in(_:values, _:values*) : =>booleans
Rule
is-in(V:values ,V′:values, V*:values*) ~> or(is-equal(V, V′), is-in(V, V*))
Rule
is-in(V:values, ( )) ~> falseFuncon
index(_:natural-numbers, _:values*) : =>values?index(N, V*) gives the Nth element of V*, if it exists, otherwise ( ).
Rule
index(1, V:values, V*:values*) ~> V
Rule
natural-predecessor(N) ~> N′
-----------------------------------------------------------------
index(N:positive-integers, _:values, V*:values*) ~> index(N′, V*)
Rule
index(0, V*:values*) ~> ( )
Rule
index(_:positive-integers, ( )) ~> ( )Funcon
third(_:values, _:values, _:T, _:values*) : =>T
Rule
third(_:values, _:values, V:T, V*:values*) ~> VFuncon
first-n(_:natural-numbers, _:(T)*) : =>(T)*
Rule
first-n(0, V*:(T)*) ~> ( )
Rule
natural-predecessor(N) ~> N′
-----------------------------------------------------------------
first-n(N:positive-integers, V:T, V*:(T)*) ~> (V,first-n(N′, V*))
Rule
first-n(N:positive-integers, ( )) ~> ( )Funcon
drop-first-n(_:natural-numbers, _:(T)*) : =>(T)*
Rule
drop-first-n(0, V*:(T)*) ~> V*
Rule
natural-predecessor(N) ~> N′
-----------------------------------------------------------------------
drop-first-n(N:positive-integers, _:T, V*:(T)*) ~> drop-first-n(N′, V*)
Rule
drop-first-n(N:positive-integers, ( )) ~> ( )Funcon
reverse(_:(T)*) : =>(T)*
Rule
reverse( ) ~> ( )
Rule
reverse(V:T, V*:(T)*) ~> (reverse(V*), V)Funcon
n-of(N:natural-numbers, V:T) : =>(T)*
Rule
n-of(0, _:T) ~> ( )
Rule
natural-predecessor(N) ~> N′
--------------------------------------------------
n-of(N:positive-integers, V:T) ~> (V, n-of(N′, V))Funcon
intersperse(_:T′, _:(T)*) : =>(T, (T′, T)*)?
Rule
intersperse(_:T′, ( )) ~> ( )
Rule
intersperse(_:T′, V) ~> V
Rule
intersperse(V′:T′, V1:T, V2:T, V*:(T)*) ~> (V1, V′, intersperse(V′, V2, V*))