Arrays & Slices
Array length is part of the type and must be known at compile time.
Arrays
Section titled “Arrays”Int[3] values = [1, 2, 3];
// Length mismatch is an error.// Int[5] bad = [1, 2, 3];Heap arrays use an owning pointer:
Int[3]^ owner = new [1, 2, 3];print(owner.length);Length Inference
Section titled “Length Inference”Use _ in the array length or infer the whole type:
_ a = [1, 2, 3];Int[_] b = [1, 2, 3];Int[3] c = [1, 2, 3];Mutability
Section titled “Mutability”Element mutability and outer binding mutability are separate layers:
Int![_] items = [1, 2, 3];items[1] = 4;
Int[_]! slot = [1, 2, 3];slot = [4, 5, 6];
Int![_]! both = [1, 2, 3];both[1] = 4;both = [4, 5, 6];Nested Arrays
Section titled “Nested Arrays”Jiang does not need a separate multidimensional array form. Repeated array suffixes build nested arrays:
Int[2][3] matrix = [[1, 2], [3, 4], [5, 6]];
matrix[0]; // [1, 2]matrix[0][1]; // 2Read Int[2][3] as Int -> Int[2] -> Int[2][3].
Int?[2][3] nullable_items = [[1, null], [3, 4], [5, 6]];Int?[2]?[3] nullable_rows = [[1, null], null, [5, 6]];Slices
Section titled “Slices”T[] is a runtime-length view over contiguous storage. It does not own the storage.
Int[_] values = [1, 2, 3];Int[] view = values[..];
print(view.length);Indexing a slice can produce an element reference:
_ item_ref = view[1]$.ref();Many Raw Pointers
Section titled “Many Raw Pointers”T[*] is a raw pointer form for contiguous elements without a length:
UInt8[*] data;Int length;
UInt8 first = data[0];T* is a single-object raw pointer and is not used for free position movement. Use T[*] for
position-based contiguous-memory access, and use T[] when Jiang code needs a length-bearing view.