Arrays
Arrays are an aggragate data type that can store a fixed number of elements of a fixed type.
Important
You must import stdlib or define printf(strlit, ...) and exit(i32) to use variable index
instantiation
define main() {
x = [0, 1, 2, 3, 4, 5]; // variable `x` is of type `i32[6]`
}
or, alternatively:
define main() {
x = [0; 6]; // variable `x` is of type `i32[6]`
}
Note
The expression inside an array instatiated in the way above will NOT be the same. For example calling random() will generate random values for ALL the locations, not just a single random value coppied across all indexes. so, doing [random(); 6] will look something like [343, 26534, 45654, 4345, 1236594, 43965]
indexing arrays
To get a value inside an array, you need to index it. Index’s start at zero and not at one.
define main() {
x = [0, 1, 2, 3, 4, 5]; // variable `x` is of type `i32[6]`
println(x[2]); // get value at index 2 (the number `2` in this case.)
}
putting a value at an index
To get a value inside an array, you need to index it.
define main() {
x = [0, 1, 2, 3, 4, 5]; // variable `x` is of type `i32[6]`
x[3] = 16; // replace value at index 3 with 16
}