List

A List represents a sequence of values.

let empty_list be list

The sequence of elements must follow the Oxford comma rule.

let names be list with "alice", "bob", and "charlie"

Lists are zero-indexed and may store values of different types.

let wild_list be list with true, 42, and "hello world"

Usage

List elements can be accessed using the at operator.

let names be list with "alice", "bob", and "charlie"
let bob be names at 1
print bob # "bob"

As an Iterable, a list can be iterated on with for each.

let numbers be list with 1, 2, and 3

for each number in numbers do
  print number

Static Functions

Returns a new List with length amount of value.

Constructor

Creates a new List copying the values from the given list.

Getters

Returns the number of elements in the list.

A getter that returns an Iterator to iterate over the list elements.

Methods

Returns a string representation of the list, or "list" if empty.

let names be list with "alice", "bob", and "charlie"
print names's to_string # list with alice, bob, and charlie

Returns a string representation of the list as an array in JSON format.

Returns a new list that is a slice of the original list. If end is not specified, it defaults to the length of the list.

let names be list with "alice", "bob", and "charlie"
let sliced_names be names's to_slice with 1, and 2
print sliced_names # list with just bob

Appends a value to the end of the list.

let names be list with "alice", and "bob"
names's append "charlie"
print names # list with alice, bob, and charlie

Prepends a value to the start of the list.

let names be list with "bob", and "charlie"
names's prepend "alice"
print names # list with alice, bob, and charlie

Inserts a value at a specific index (shifts values accordingly).

let numbers be list with 1, 2, and 3
numbers's insert_at with 1, and 4
print numbers # list with 1, 4, 2, and 3

Removes a value at a specific index (shifts values accordingly).

let numbers be list with 1, 2, and 3
numbers's remove 1
print numbers # list with 1, and 3

Returns the index of the first occurrence of a value in the list.

let numbers be list with 1, 2, and 3
let index be numbers's find_index 2
print index # 1

Returns a new list that is the concatenation of the two lists.

let numbers1 be list with 1, 2, and 3
let numbers2 be list with 4, 5, and 6
let concatenated_numbers be numbers1's concatenated numbers2
print concatenated_numbers # "list with 1, 2, 3, 4, 5, and 6"
print "hello world"