Language: Lists
Lists are a collection of zero or more values.
Lists can be created using by wrapping values in []
and separating them
by commas. An optional trailing comma is allowed. List elements can be
differing types. Examples:
A list can be sliced to create sublists. The set operators can be used to test for value inclusion in a list.
Accessing Elements
List elements can be accessed with the syntax name[index]
where
index
is zero-indexed.
A negative index accesses the list in reverse. It is the same as reversing a list and then using a positive index. Similar to a positive index, it is bounded by the length of the list as a negative value.
Accessing beyond the length of the list results in undefined.
Examples:
List Append
Values can be appended to a list using the built-in append function.
This modifies the list in-place and returns
undefined. For more information on
why append
behaves this way, please read the full documentation for the
append function.
List Concatenation
Two lists can be concatenated using the +
operator or the shorthand
+=
assignment operator. For the +
operator, a new list is returned.
For +=
, the left-hand list is modified in place.
Examples:
List Length
The length of a list can be retrieved using the length function.
Examples:
Removing Items From a List
You can use a combination of list concatenation and slicing to remove elements from a list.
The shorthand shown here is effectively the same as a[0:2] + a[3:length(a)]
,
which creates a new list out of the concatenation two sub-lists composed of the
first two elements, and the rest of the list starting at index 3. This
effectively removes the 3rd element from the list (index 2).
List Comparison
Lists may be compared for equality. Lists are equal if they are of equal length and their corresponding elements are comparable and equal. Lists with the same elements but in a different order are not equal.
List comparison speed is O(N), meaning that the speed of the comparison is linearly proportional to the number of elements in the list. The more elements, the more iterations that are necessary to verify equality.
The N-value quoted above should account for the sum of the elements of all lists in the subjects of comparison, as list comparison will recurse into these lists to check for equality.