Skip to main content

Collection built-ins

These functions build and take apart [T] sequences.

list

list(first: T, rest: T...) -> [T]

Builds a sequence from one or more values of the same type.

ArgumentTypeRequirementDescription
firstTRequired, positionalFirst element. Its type becomes the element type.
restT...Zero or more positionalFurther elements, all of the same type as the first.

Returns [T]. The values, in order.

let widths = list(80., 120., 160.);

cons

cons(value: T, tail: [T]) -> [T]

Prepends one value to an existing sequence.

ArgumentTypeRequirementDescription
valueTRequired, positionalNew first element.
tail[T]Required, positionalThe rest of the sequence. The empty literal [] works for any element type.

Returns [T]. A new sequence starting with value.

let values = cons(10., cons(20., []));
head(sequence: [T]) -> T

Returns the first element of a sequence.

ArgumentTypeRequirementDescription
sequence[T]Required, positionalA non-empty sequence.

Returns T. The first element.

Fails at run time if the sequence is empty.

tail

tail(sequence: [T]) -> [T]

Returns every element after the first.

ArgumentTypeRequirementDescription
sequence[T]Required, positionalA non-empty sequence.

Returns [T]. Everything after the first element.

Fails at run time if the sequence is empty.

range_full

range_full(start: Int, stop: Int, step: Int) -> [Int]

Builds an integer range from a start, stop, and step.

ArgumentTypeRequirementDescription
startIntRequired, positionalFirst value.
stopIntRequired, positionalExclusive upper bound.
stepIntRequired, positionalStep between values.

Returns [Int]. The range as a sequence.

For the common case of counting from zero, use std::range(stop).