Collections

Arrays

string[] declares an array type. This is an immutable ordered collection of elements.
Some common array operations are:

x ~ xs Prepends an element x on the left of the array xs.
xs ~ x Appends an element x on the right of the array xs.
xs ~~ ys Concatenates two arrays.
xs[3] Accesses an element at a 0-based index.
for x : xs; x + 1 Loops over the array and returns a new array. Explained in "For" and "with" expressions.
main void() xs string[] = "a", "b" info log "{xs.to::json}" ys = xs ~ "c" info log "{ys.to::json}" zs = xs ~~ ys info log "{zs.to::json}"

Creating an array uses the same syntax as creating a record, meaning it is calling a function called new. This function is variadic, meaning it can take any number of arguments.

Slicing

xs[i] gets the ith element of a array. Indices start at 0.
xs[end - j] gets the jth last element. end is one past the last element, so j should not be 0.
xs[i .. j] gets elements i, i + 1, etc., up to (but not including) j.
xs[i .. end] discards the first i elements.
xs[0 .. end - j] discards the last j elements.

main void() xs nat[] = 0, 1, 2 info log "{xs[end - 1]} == {xs[2]}" info log "{xs[1 .. end]} == {xs[1 .. 3]}" info log "{xs[0 .. end - 1] == xs[0 .. 2]}" info log "{xs[2 .. 1]}" # will throw show string(a nat[]) a.to::json show

Mutable array

string mut[] declares a mutable array.
Use ~= and ~~= to append elements or arrays. (There is no efficient prepend; there is col/mut-dequeue for that.)

main void() xs string mut[] = "a", "b" info log "{xs.to::json}" xs ~= "c" info log "{xs.to::json}" xs ~~= xs xs[4] := "B" info log "{xs.to::json}"

Maps

string[nat] declares a map from nats to strings.

main void() m string[nat] = (1, "one"), (2, "two") info log m[1]! m2 = m ~ (1, "uno") info log m2[1]!

Mutable maps

string mut[nat] declares a mutable map.

main void() m string mut[nat] = (1, "one"), (2, "two") info log m[1]! m[1] := "uno" info log m[1]!

Shared collections

There is also t shared[] and v shared[k] which work like t mut[] and v mut[k] but are shared.

Other collections

There are other collections like col/set and col/mut-set in the col directory.
There is also a col/collection module for containing functions that work on many kinds of collection.