Skip to main content
Version: 1.6.0

Adding

Lists can be augmented by adding an element before the head (or, in terms of stack, by pushing an element on top). This operation is usually called consing in functional languages.

The cons operator is infix and noted ", ...". It is not symmetric: on the left lies the element to cons, and, on the right, a list on which to cons.

const short_list : list<int> = [1, 2, 2];
// long_list == [5,1,2,2]
const long_list : list<int> = [5, ...short_list];

There is also a predefined function List.cons:

// longer_list == [6, 5, 1, 2, 2]
const longer_list = List.cons(6, long_list);

See predefined namespace List.