Skip to content
Bill Hails edited this page Oct 21, 2018 · 14 revisions

Lists are immutable. All the list operators make and return copies if necessary.

A list is written between [ and ] with commas as separators. For example:

[5 + 5, 12]; // [10, 12]

The empty list is written [] and pronounced "null".

There are a few list operators, namely:

@ (cons)

Creates a new list by prepending its lhs to its rhs (which must be a list of the same type):

12 @ [13, 14];

is [12, 13, 14], but

true @ [13, 14]

is a type error: bool != int. See Typedef for ways to create lists of mixed type.

@@ (append)

Creates a new list by making a copy of the lhs with the rhs appended:

[12, 13] @@ [14, 15]; // [12, 13, 14, 15]

length

Returns the length of a list:

length([10, 11]); // 2

Because lists are immutable they store their own length and length operates in O(1) time.

head

Returns the first element of the list:

head([1, 2, 3]); // 1

tail

Returns all but the first element of the list:

tail([1, 2, 3]); // [2, 3]

Up: Home

Next: Strings and Chars

Clone this wiki locally