List
A list value is a sequence of values. Lists are zero-indexed and dynamic. It may store values of different types.
let team_members be list with
object with name as "alice", age as 30, and role as "lead developer",
object with name as "bob", age as 25, and role as "developer",
object with name as "charlie", age as 35, and role as "developer", and
object with name as "dave", age as 40, and role as "designer"Definition
An empty list can be defined using list as the value.
let empty_list be listA list can be defined with values using with ... and following the Oxford comma rule.
let names be list with "alice", "bob", and "charlie"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"Using for each ... in ... do ... you can iterate over the elements in a list.
let numbers be list with 1, 2, and 3
for each number in numbers do
print numberGetters
Returns the number of elements in the list.
let numbers be list with 1, 2, and 3
print numbers's length # 3Methods
Returns a string representation of the list, e.g. "list with 1, 2, and 3", "just Alice", or "list" if empty.
let numbers be list with 1, 2, and 3
let string be call numbers's to_string
print string # "list with 1, 2, and 3"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 call 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"
call names's append with just "Charlie"
print names # "list with Alice, Bob, and CharliePrepends a value to the start of the list.
let names be list with "Bob", and "Charlie"
call names's prepend with just "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
call 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
call numbers's remove with 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 call numbers's find with 2
print index # 1Returns 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 call numbers1's concatenated with numbers2
print concatenated_numbers # "list with 1, 2, 3, 4, 5, and 6"