So far, we have explored the string and number type. These are great for exactly that, text and numerical values. What if we want to store a collection of strings and numbers? Meet your companion, the list.
obj x = [];
The list type is a dynamic collection that can be grown, shrunk, indexed, combined, and more. It can store any type separated by commas:
obj x = ["Object in the list", 1, 2, 3, 4];
To access a value in a list, we can index it:
obj x = [1, 2, 3, 4];
# 'retrieve' will get the value at index 'i'
obj value_in_list = retrieve(x, 0); # in this case, index 0 is the first item in the list
To add a value to a list, we can push it:
obj x = [];
# 'push' will add the value to the list
push(x, "value");
To get rid of a value in a list, we can remove it:
obj x = [1, 2, 3, 4, 5];
# 'remove' will remove the value at an index
remove(x, 4); # list looks like: [1, 2, 3, 4]
To combine two lists, we can append them:
obj x = [1, 2];
obj y = [3, 4];
# 'append' will combine the two lists with each other
append(x, y); # list looks like: [1, 2, 3, 4]
And lastly, we can reverse the values in a list:
obj x = [3, 2, 1];
# 'reverse' will reverse all the values in a list
reverse(x);