Arrays
Arrays are Munos's structured-data primitive. Every array has a fixed element type known at compile time, written T[].
Declaration
Two forms:
var scores: i32[] = [10, 20, 30] // literal: size and values from the initializer
var slots: i32[10] // sized: ten elements, zero-filledA sized declaration is itself an initializer — its elements are zero-filled (numbers → 0, bool → false, string → ""). The "must-initialize" rule applies to arrays; the size is the initialization.
Indexing
Zero-based, square brackets. Out-of-bounds access traps at runtime.
var scores: i32[] = [10, 20, 30]
var first = scores[0] // 10
scores[1] = 99Length and capacity
An array header tracks two numbers:
- length — how many elements are currently in use.
len(x). - size (capacity) — how many it can hold.
size(x).
len(scores) // current number of elements (also works on strings → byte length)
size(scores) // capacityFor both literal and sized declarations the array starts full — len == size. They differ only after you pop (see below).
Growable operations
push and pop change the length within the fixed capacity. Capacity never grows.
push(arr, value) // append at index len, bump length; TRAPS if len == size
pop(arr) // remove and return the last element; TRAPS if len == 0Because a freshly declared array is already full, the working pattern is pop to make room, then push:
var a: i32[3]
a[0] = 10; a[1] = 20; a[2] = 30
pop(a) // 30 — len now 2
pop(a) // 20 — len now 1
push(a, 99) // a[1] = 99, len now 2
push(a, 7) // len now 3
// push(a, 1) // would trap: len == size == 3push's value must match the element type; pop returns the element type.
copy
copy(x) returns an independent duplicate of an array or string — a fresh backing buffer with size == len == src.length.
var a: i32[] = [1, 2, 3]
var b = copy(a)
b[0] = 99 // a[0] is still 1copy accepts arrays and strings only — not structs (duplicate a struct by copying its fields).
Parallel arrays: the record idiom
Munos has no array-of-structs-by-value collection type. For a set of records — every player's x, y, and name — the idiom is parallel arrays indexed by the same key:
var playerX: u8[64]
var playerY: u8[64]
var occupied: bool[64]
// player i's state is (playerX[i], playerY[i]), valid when occupied[i]This is the backbone of server-side per-player state — see Server & slots. For a single record, use a struct.
Summary of array forms
| Form | Result type | Notes |
|---|---|---|
len(a) | i32 | current length; also strings |
size(a) | i32 | capacity |
push(a, v) | — | append; traps at capacity |
pop(a) | element | remove last; traps when empty |
copy(a) | same as a | independent duplicate (arrays/strings) |