Arrays map a fixed range of integer indices starting at 0 to a set of values of the same type. The run-time cost of accessing the value of an arbitrary index in an array is typically constant (disregarding caching and similar effects).
An array in fuzion is a generic feature
Array<T> that is
part of the Fuzion standard library. Apart from some intrinsic functions for an
efficient implementation, arrays are features just as any other feature in
Fuzion. They can be used as types, as parents for inheritance, as generic
Since Fuzion does require values to be initialized before they are used, arrays must provide a means to initialize their elements when they are created. Thus an Array receives a function argument that provides the initial values for its elements. This function can also be used to fill the array with data.
Array Initialization Function
Here is a small example that fills an array of
i32 values with
the squares of the corresponding indices and then prints the mapping:
Direct Array Initialization
As an alternative to an initialization function, syntactic sugar allows the
direct initialization of an array from a list of expressions enclosed in
TBW / NYI: How to distinguish mutable and immutable arrays?