In Nosica, all defined arrays inherit from the Array interface.

The Array interface defines several methods/properties :

interface Array { const word length(const word dimension) const; const word property length() const; const word property dimension() const; }

The length() methods return the number of elements in a dimension. The length property returns the total number of elements in the array. The dimension property returns the total number of dimensions.

You can find the definition of the Array interface in Nosica'standard library. (stdlib/net/nosica/lang)

For example, let's say I define this type in my code :

sub someFunctionInSomeClass() { int[,] t = new int[5,10]; }

The int[,] is a new multi dimensional array type. This type has 2 dimentions. (result of dimension property) In first dimension, there is 5 elements. (result of length(0) method) In second dimension, there is 10 elements. (result of length(1) method) The total number of elements is 5 * 10 = 50 elements (result of length property)

When the type int[,] is instantiated by the compiler, additional methods are defined :

class int[,] implements Array { // linear array properties public int property [](const word linearDim) const; public sub property [][const int value, const word linearDim);

// multi dimensional array properties public int property [](const word dim0, const word dim1) const; public sub property [](const int value, const word dim0, const word dim1); }

The two first array properties allows us to treat the array as a mono dimensional array. That means that linearDim must always fits in [0, length[.

The two last array properties allows us to access the array as a true multi dimensional array. That means that

- dim0 must fit in [0, length(0)[
- dim1 must fit in [0, length(1)[

Of course, it is possible to define array of arrays ...

No comments yet