Collections
Typed dynamic, fixed and nested arrays and dictionaries.
Arrays
func main() {
local var scores int32[] = [10, 20, 30]
local var fixed int32[3] = [1, 2, 3]
local var nested int32[][] = [[1, 2], [3]]
scores[0] = 15
print(scores[-1])
print(nested[0][1])
}Value[] declares a dynamic array andValue[amount] declares an array with a fixed length. Add another pair of brackets for each nesting level. An array literal requires a declared array type; all its values must match the element type.
Array indexes may use any integer type. Zero addresses the first element. Negative indexes count backwards, so -1 addresses the last element. An invalid index stops the program with a runtime error; fixed literal indexes are also checked at compile time.
Dictionaries
func main() {
local var scores dictionary[string, int32] = [
"Bob": 100
"Alice": 80
]
local var fixed dictionary[string, int32, 2] = ["A": 1 "B": 2]
scores["Bob"] = 120
scores["Danny"] = 70
for score, name in scores {
print(name + ": " + score)
}
}A dictionary type is written dictionary[Key, Value]. A third type argument fixes its entry count. Keys may be strings, booleans, or any integer type. Duplicate literal keys are rejected.
Assigning to a missing key adds it to a dynamic dictionary. Reading a missing key with indexing stops the program; use get(key, fallback) when absence is expected. Fixed dictionaries cannot add or remove keys.
Iteration and mutation
Array loops provide each value and, optionally, its index. Dictionary loops provide each value and, optionally, its key. Existing values may be replaced during iteration, but the collection cannot be resized until iteration ends.
Equality and copying
Arrays compare element by element. Dictionaries compare keys and their corresponding values regardless of insertion order. Assignment shares a collection; useduplicate() or duplicate_deep() for an explicit copy.