array
Capy
[element_type]
An array holds a variable number of values of one type, written [s32], [string], and so on. Literals use square brackets and indexing is zero-based:
function RENDER(request : dval) {
var scores := [10, 20, 30]
print(scores[0], " ", length(scores), "\n")
}Identity is shared
Assignment, parameter passing, returning and capturing all share one array — they do not copy it. A function that mutates an array's contents changes what the caller sees:
function append_total(values : [s32]) {
values.push(60)
}
function RENDER(request : dval) {
var values := [10, 20]
append_total(values)
print(length(values), " ", values[2], "\n")
}The binding itself is immutable, so values = [3] inside that function is a compile error — you can change the contents, not which array the name refers to. Growth preserves identity, so a push that reallocates is still the same array to every holder.
Methods
push, pop, insert, remove, clear, reserve, resize and capacity are called on the array itself. length() returns the count.
Iteration
A for loop reads items in order, with an optional s64 index after the value:
function RENDER(request : dval) {
var names := ["Ada", "Grace"]
for name, index := names {
print(index, ": ", name, "\n")
}
}The loop rechecks the current length each iteration, so it stops safely after a shrink and can visit items appended while it runs. The loop value is a copy of the item, not an assignable position — use an index to replace one.
Example
Capy
var scores := [10, 20, 30] scores.push(40) print(scores[0], " ", length(scores), "\n")