– Typee Documentation –

4 – Built-in Containers

4.1 – Arrays

Arrays are indexable containers with fixed size and specified type for their content. They may get multiple dimensions. Dimensions sizes must be specified at declaration time with constant or scalar integer values.

4.1.1 Arrays Declaration

The formal EBNF specification of the syntax of arrays declaration in Typee is:

<array declaration> ::= [<const>] <array type> <identifier>
                            [ '=' <array content> ] ';' 

<array content>     ::= '[' (<items list> | <array content>) ']' 

<array type>        ::= 'array' <contained type> <dimensions>

<contained type>    ::= '<' <types list> '>' 

<dimensions>        ::= '[' (<integer number> | <dotted name>) ']' 
                            ( '[' (<integer number> | <dotted name>) ']' )*

<dotted name>       ::= <identifier> ( '.' <identifier> )*

<items list>        ::= <expression> ( ',' expression )*

<templated type>    ::=  <dotted name>
                            [ '<' <types and exprs list> '>' ]

<types list>        ::= <type>  |  '(' <type> ( ',' <type> )* ')' 

<type>              ::= [ 'const' ] (<scalar type>   |
                                     <built-in type> |
                                     <dotted name>)

Of course, when the array content is defined at declaration time, the content has to be of the correct type and the number of dimensions has to be respected.
Examples:

const array<uint32>[7] primes = [1, 2, 3, 5, 7, 11, 13];

array<uint8>[576][720] grey_image;
// 576 lines with 720 pixels (256-grey-levels) each

array<(uint8, uint8, uint8)> [1200][1920] color_background;
// 1200 lines with 1920 pixels (red, green, blue 256-levels) each

const array<float32>[3][3] identity_matrix = [ [1.0, 0.0, 0.0],
                                               [0.0, 1.0, 0.0],
                                               [0.0, 0.0, 1.0] ];

Dimension sizes can be specified with constant identifiers. But they cannot be specified with identifiers of variables. They must be integers.
Example:

const uint8 MAX_SIZE = 128;
uint32 array<float64> [MAX_SIZE][MAX_SIZE][MAX_SIZE] my_array;

4.1.2 Arrays Indexation

There are three ways for indexing an array: subscription, slicing and comprehension:

<subscription or slicing>   ::= <subscription or slicing'>
                                    (<subscription or slicing'>)*
<subscription or slicing'>  ::= '[' <expression>
                                    ( ']'                     |
                                      <if comprehension> ']'  |
                                      <slice form> <slice end> )
<for comprehension>         ::= 'for' '(' <target list> 
                                    'in' <or test> <iter comprehension> ')' 

<if comprehension>          ::= 'if' '(' (<or test> | <unnamed func>) ')' 
                                    <iter comprehension>

<iter comprehension>        ::= [ <for comprehension>  |  <if comprehension> ]

<slice end>                 ::= ']'  |  ')' 

<slice form>                ::= ':' [<expression>]  [ ':' [<expression>] ]
4.1.2.1 Subscription

Subscription, or indexing, only involves the use of a single expression between two brackets. It directly accesses the content of the indexed entity. If the array gets one dimension only, the subscription gets access to the contained item at this index in the array. It the array gets two dimensions, the first subscription gets access to the indexed line in the array. The use of a secondary subscription in this line directly accesses the item contained at this index in this line of the array. Easy to extend to more than two dimensions. Indexing in Typee starts at 0.

As with Python, negative subscripting is allowed. It starts from -1 which is the index of the very last item. Index -2 stands then for the index of the item that is before the last one and index -3 stands for the antepenultimate one, etc.

Indexing items out of the bounds of an array raises an exception OutOfBoundsException. Under some circumstances, this may be detected at translation time. Typee translators will set an error then. But most of the time, out-of-bounds errors will only be detectable at run-time. OutOfBoundsException will then be raised.
Indexing a non existing dimension raises an exception ArrayDimensionException.

Let’s have a few examples:

array<uint8>[4][3] the_array = [ [ 0, 1, 2],
                                 [10,11,12],
                                 [20,21,22],
                                 [30,31,32] ];

print( the_array[0] );      // prints "[0, 1, 2]"
print( the_array[3] );      // prints "[30, 31, 32]"
print( the_array[3][2] );   // prints "32"

the_array[2][1] = 121;
print( the_array[2] );      // prints "[20, 121, 22]"

print( the_array[-1][-2] ); // prints "121"
print( the_array[ 1][-1] ); // prints "12"
4.1.2.2 Slicing

Slicing is a well known concept in Python. It selects a range within an array. Easier to understand with a few examples.

First, about slicing itself:

[start:end]
// means "indexing of all items ranging
// from index start up to index end included".

[start:end)
// means "indexing of all items ranging
start up to index end excluded".

[start:end:step]
// means "indexing of all items ranging
// from index start up to index end included
// by steps of value step".

[start:end:step)
// means "indexing of all items ranging
// from index start up to index end excluded
// by steps of value step".

Slicing may be done in reverse order:
[10:0:-1] is a slice form index 10 down to index 0 included with a step of -1.

Bounds as well as step values may be omitted:
[4::2] is a slice from index 4 up to max index included, with a step of 2 (i.e. indexes 4, 6, 8, …; max index being the default value for end)

[::2] is a slice from index 0 up to max index included, with a step of 2 (i.e. indexes 0, 2, 4, …; 0 being the default for start value and max index being the default one for end)

[0:10] is a slice from index 0 up to index 10 included, with a step of 1 (1 is the default value for step)

[:] is a slice from index 0 up to max index included, with a step of 1 (these are the three respective default values for start, end and step).

Last exemple:
[::10] is a slice from index 0 up to max index included, with a step of 10.

Then, about slicing in an array:

array<uint8>[4][3] the_array = [ [ 0, 1, 2],
                                 [10,11,12],
                                 [20,21,22],
                                 [30,31,32] ];

print( the_array[0:2] );
// prints "[[0, 1, 2], [10, 11, 12], [21, 21, 22]]"

print( the_array[3:2:-1] );
// prints "[[30, 31, 32], [20, 21, 22]]"

print( the_array[0:1][0:2) );
// prints "[[0, 1], [10, 11]]"

the_array[1:2][1] = [100, 100];
print( the_array );
// prints "[[0, 1, 2], [10, 100, 12], [20, 100, 22], [30, 31, 32]]"

print( the_array[2][2:0:-1) );
// prints "[22, 21]", last index (0) being excluded from the slice

print( the_array[2][-1:-3:-1) );
// prints "[22, 21]", last index (-3) being excluded from the slice
4.1.2.3 Comprehension

Comprehension is also a well known concept in Python. It selects items according to some condition within a range.
Let us see a few complete examples, using the array defined in previous subsection:

for( uint8 i in [0:3] ) {
    print( i, '-', the_array[i][j] if( j > 0 ) for( uint8 j in [0:2] ) );
// prints:
// "0 - 1 2
//  1 - 11 12
//  2 - 21 22
//  3 - 31 32"

for( uint8 i in [0:3] ) {
    print( i, '-', the_array[i][j] if( the_array[i][j] > 20 )
                                       for( uint8 j in [0:2] ) );
// prints:
// "0 - 
//  1 - 
//  2 - 21 22
//  3 - 30 31 32"

This is a powerfull concept inherited from Python that you will really enjoy to use once you will get used to. It allows very concise and sure programmation.

4.1.3 Arrays Iterations

Arrays are iterable. Iterating through an array is done via statement for.

A one-dimensional array can be fully iterated this way:

array<uint32> [20] the_array = [ i for( uint32 i in [0:20) ) ];
// comprehension programming is powerfull

for( uint32 val in the_array )
    print( val );
// prints "0" to "19" on 20 successive lines

Iterating multiple dimensional arrays acts the same, but the iterating runs through external dimensions first. For instance:

const uint8 LINES = 4;
const uint8 COLS  = 3;

array<uint32>[LINES][COLS] the_array =
    [ [10*i+j for( uint32 j in [0:COLS) )] for( uint32 i in [0:LINES) ) ];

for( array<uint32>[COLS] line in the_array ) {
    // iterating is done on first dimension
    // the iteration runs then through lines
    // and every returned item is a line of COLS cells

    for( uint32 cell_value in line ) {
        // iterating is done then on second dimension
        // the iteration is done through the extracetd line
        // and every returned item is the value contained in current cell
        
        print( cell_value );
    }
    print();
}

// prints on successive lines the whole content of the array
// - first line first, one cell value per line,
//   with a line gap before second line
// - next lines then, one cell value per line,
//   with a gap line between each of them

4.1.4 Arrays Manipulations

Typee provides built-in functions for the manipulation of arrays. They are of a few kinds and are all presented in next sub-sections. They all are available whatever the type of the contained items in an array, except for statistics functions which are available for only integer and float contained values.

All of these functions are methods-like. They can be applied to an array as would be built-in methods:
my_array.array_function(...)

4.1.4.1 Items counting

How many items in an array?

const uint32 count()

Returns the number of items contained in an array.
Example:

array<uint8>[256][256] image;
print( image.count() );  // prints: 65536
const uint32 count( const ? item )

Returns the number of occurences of argument item contained in an array.
Example:

array<uint8>[3][3] matrix = [ [1,0,0], [0,1,0], [0,0,1] ];
print( matrix.count(0), matrix.count(1), matrix.count(2) );  // prints: 6 3 0
4.1.4.2 Items searching

Is some item present in an array? What is the index of the first found one? What are the indexes of many of them? What are the indexes of all of them?

const bool operator in ( const ? item, const array container )

Keyword in checks for the presence of an item into an array. Result is either true if item has been found in the array or false otherwise.
Examples:

array<uint16>[] the_array = [0,1,2,3];
print(  2 in the_array );  // prints true
print( 10 in the_array );  // prints false

array<uint8>[][] the_array = [ [0,1], [10,11] ];
print(  2 in the_array );  // prints false
print( 10 in the_array );  // prints true
const bool operator not in ( const ? item, const array container )

The association of these two keywords is the counterpart of keyword in.
Examples:

array<uint16>[] the_array = [0,1,2,3];
print(  2 not in the_array );  // prints false
print( 10 not in the_array );  // prints true

array<uint8>[][] the_array = [ [0,1], [10,11] ];
print(  2 not in the_array );  // prints true
print( 10 not in the_array );  // prints false
const ? in (uint32, list) index( const ? item )

Returns the index in the array of the first found occurence of argument item. Returns special value none if item is not found in the array.
Example:

array<uint16>[] the_array = [0,10,20,30];
print( the_array.find( 2) );  // prints none
print( the_array.find(10) );  // prints 1

array<uint8>[][] the_array = [ [0,1], [10,11] ];
print( the_array.find( 2) );  // prints none
print( the_array.find(10) );  // prints [1,0]
const list indexes( const ? item, const uint32 n_max )

Returns a list of indexes of the n_max first ocurences of argument item in the array. If none is found, returns an empty list. Notice that lists are explained in the next section of this documentation.
Example:

array<uint8>[3][3] unit_mat =
    [ [1,0,0],
      [0,1,0],
      [0,0,1] ];
print( unit_mat.indexes(1,2) );      // prints [[0,0], [1,1]]
print( unit_mat.indexes(0,3) );      // prints [[0,1], [0,2], [1,0]]
print( unit_mat[-1:].indexes(0,3) ); // prints [[2,1], [2,0], [1,2]]
const list indexes( const ? item )

Returns the list of indexes of all occurences of argument item in the the array. If none is found, returns an empty list. Notice that lists are explained in the next section of this documentation.
Example:

array<uint8>[3][3] unit_mat =
    [ [1,0,0],
      [0,1,0],
      [0,0,1] ];
print( unit_mat.indexes(1) );      // prints [[0,0], [1,1], [2,2]
print( unit_mat.indexes(0) );      // prints [[0,1],[0,2],[1,0],[1,2],[2,0],[2,1]]
print( unit_mat[-1:].indexes(1) ); // prints [[2,2], [1,1], [0,0]]
4.1.4.3 Items clearing
array clear()

Sets all items contained in the array to their “default” value. Returns a reference to the operated array for calls to methods to be cascadable.

  • for integers, the default value is 0
  • for floats, the default value is 0.0
  • for chars, the default value is ' '
  • for strings, the default value is the empty string ""
  • for containers, the default value is the empty container except for arrays, for which every item is set to its default value
  • for instances of classes, the default value is the instance created with the “default” constructor (the one with no arguments. If no default constructor is defined, then the default value is none

Example:

array<uint8>[2][2] unit_mat;
unit_mat.clear();
print( unit ); // prints [[0,0, [0,0]]
unit_mat[0][0] = unit_mat[1][1] = 1;
print( unit ); // prints [[1,0, [0,1]]
4.1.4.4 Array copying and referencing

Copying an array means creating a new array with same size in heap or stack memory, then duplicate the whole content from origin to destination. Any further transformation done on one of the arrays will not modify the other one.

Referencing an array is to be understood as creating an alias or defining a pointer to the original array. Any transformation applied to the array will be reflected through its reference. Any further transformation applied to its reference will be applied in the original array.

Syntax is straightforward. Let’s illustrate it with simple examples:

array<uint8>[4] src_array = [0, 1, 2, 3];
array<uint8>[4] dst_array;

dst_array = src_array;          // array copy
dst_array[0] = 10;
print( src_array, dst_array );  // prints [0,1,2,3] [10,1,2,3]

dst_array = &src_array;         // array reference
print( src_array, dst_array );  // prints [0,1,2,3] [0,1,2,3]
src_array = [10, 20, 30, 40];
dst_array[0] = 100;
print( src_array, dst_array );  // prints [100,20,30,40] [100,20,30,40]
4.1.4.5 Array sorting

There are two main classes of sorting algorithms: unstable and stable. Stable sorting means that equal items will stay ordered the same way they where before sorting. Such sorts are most of the time a little bit slower than unstable sorts, but they are much appreciated because of this particular main characteristic.

It appears that some other programming languages offer by default a stable sorting function, based on the Timsort algorithm. This is a hybrid algorithm, “derived from merge sort and insertion sort, designed to perform well on many kinds of real-world data.” (source: Wikipedia). This algorithm had been first introduced in [1] by Peter McIlroy in 1993 and had been implemented by Tim Peters (Timsort…) in 2002 for the Python sort() built-in function. Since then, this algorithm has been enhanced (a bug has been found) and has also been implemented for Java.
[1]: “Optimistic Sorting and Information Theoretic Complexity“, Peter McIlroy, in Proceedings of the Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 467–474, January 1993.

So, it may be that the unstable sorting function built in Typee will finally be translated into a stable version of a sorting algorithm, depending on the targeted programming language. This will enventually be the case when translating Typee code to Python and Java.

Notice that whatever the function used to sort an array, the array is always sorted in-place, i.e. the content of the array is directly modified. Applying a sort on a reference to an array will sort the original array as well. Then, sorting a constant array is illegal in Typee – such arrays are unmutable.

Finally, sorting in Typee is only applied to the mostly nested dimension of the array. For instance, should an array be two-dimensional (i.e. a matrix), every line would be sorted in-place, but no lines would be inverted together. We provide an example of this in next sub-section. Should programmers wish to sort such lines, they would have to provide a comparing function between lines and use it with one of the forms of function sort() below.

array sort()

This is the basic sort function in Typee. Arrays are sorted in ascending order by default.
Example:

array<uint8>[] the_array = [8, 4, 5, 2, 8, 0, 1, 7, 3];
print( the_array.sort() );  // prints [0, 1, 2, 3, 4, 5, 7, 8, 8]

It can be applied to any array for which content is comparable. This is the case for every scalar types in Typee: integers, floats, chars, strings and booleans (false is smaller than true in Typee). It is the case also for any object that is an instance of a class for which at least the comparison operator < has been defined or for which the hashing operator # has been defined. For example:

class C {
    C ( const int16 value ) {
        me.val = value;
    }

    const bool operator < ( const C other ) {
        return me.val < other.val;
    }

    private int16 val;
}

About sorting multi dimensional arrays, let’s illustrate this with an example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 7] ];
the_array.sort()
print( the_array );  // prints: [ [2, 4, 5, 8], [0, 1, 7, 8] ]
array sort( const int32 comp_func(const ?, const ?) )
array sort( const int32 comp_func< ItemT >(const ItemT, const ItemT )

This signature of built-in function sort() specifies the comparison function to be used for the sorting operation. Comparison functions here have to accept two arguments of any type with a contraint : they have to be comparable together. This checking might not be done at transalation time but rather at run-time. Be cautious there. These comparison functions are expected to return a signed integer value:

  • less than 0 if first argument is less than second one;
  • equal to 0 if both arguments are equal;
  • greater than 0 if first argument is greater than second one.
array stable_sort()

This function is the stable version of function sort(). It is applicable the same way than sort().

array stable_sort( const int32 comp_func(const ?, const ?) )
array stable_sort( const int32 comp_func< ItemT >(const ItemT, const ItemT) )

This function is the stable version of function sort() with a comparison function as argument. It is applicable the same way than sort().

array reverse_sort()

This is the counter part of function sort(). It sorts arrays in a descending order. It can be applied to any array for which content is comparable. This is the case for every scalar types in Typee: integers, floats, chars, strings and booleans (false is smaller than true in Typee). It is the case also for any object that is an instance of a class for which at least the comparison operator < has been defined or for which the hashing operator # has been defined.

array reverse_sort( const int32 comp_func(const ?, const ?) )
array reverse_sort( const int32 comp_func< ItemT >(const ItemT, const ItemT) )

This is the counter part of function sort() when passed a comparison function as argument. It sorts arrays in the reverse order that the comparison function results in.

array reverse_stable_sort()

This function is the stable version of fucntion reverse_sort(). It is applicable the same way.

array reverse_stable_sort( const int32 comp_func(const ?, const ?) )
array reverse_stable_sort( const int32 comp_func< ItemT >(const ItemT, const ItemT) )

This function is the stable version of function reverse_sort() with a comparison function as argument. It is applicable the same way.

4.1.4.6 Array statistics

A few statistics functions are available in Typee with arrays.

const uint64 size()

Returns the size of the array in memory with bytes as the measure unit.
Caution: while the returned value will be exact for arrays containing char, integer and float scalars, it might be not exact for strings, booleans and instances of classes. The memory space reserved for these last entities may greatly vary according to the targeted language and the final compilers or interpreters implementations which can’t be exactly known at translation time.
Example:

array<uint32>[1200][1920] image32
print( image32.size(); );  // prints 9216000, (i.e. 9_216_000)
array<int8>[1200][1920] image8;
print( image8.size(); );   // prints 2304000, (i.e. 2_304_000)
const ? min()

Returns the minimum value contained in an array. If the array contains objects rather than scalar values, the class that these objects inherit from must own a defined comparison operator <. If not, this class must otherwise define at least one char, string, integer or float casting operator or the hash operator #. If many are defined, priority for the casting before comparision will be hash first and char last, in the inverse order of previous list. If no such operator is defined, an error will occur at translation time.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 0], [8, 0, 1, 7] ];
print( the_array.min() );  // prints: 0
const ? in (uint64, list<uint64>) argmin()

Returns the index of the first minimal value found in an array. If the array is multi-dimensional, returns the list of the indexes of every dimension. If the array contains objects rather than scalar values, the class these objects inherit from must own a defined comparison operator <. If not, this class must otherwise define at least one char, string, integer or float casting operator or the hash operator #. If many are defined, priority for the casting before comparision will be hash first and char last, in the inverse order of previous list. If no such operator is defined, an error will occur at translation time.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 0], [8, 0, 1, 7] ];
print( the_array.argmin() );     // prints: [0,3] - the index of first found 0
print( the_array[0].argmin() );  // prints: 3
const list argsmin()

Returns the indexes of all minimal values found in an array. If the array is multi-dimensional, returns the list of the indexes of every dimension. If the array contains objects rather than scalar values, the class these objects inherit from must own a defined comparison operator <. If not, this class must otherwise define at least one char, string, integer or float casting operator or the hash operator #. If many are defined, priority for the casting before comparision will be hash first and char last, in the inverse order of previous list. If no such operator is defined, an error will occur at translation time.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 0], [8, 0, 1, 7] ];
print( the_array.argsmin() );    // prints: [[0,3],[1,1]]
print( the_array[0].argmin() );  // prints: [3]
const ? max()

Returns the maximum value contained in an array. If the array contains objects rather than scalar values, the class that these objects inherit from must own a defined comparison operator <. If not, this class must otherwise define at least one char, string, integer or float casting operator or the hash operator. If many are defined, priority for the casting before comparision will be hash first and char last, in the inverse order of previous list. If no such operator is defined, an error will occur at translation time.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 7] ];
print( the_array.max() );  // prints: 8
const ? in (uint64, list) argmax()

Returns the index of the first maximal value found in an array. If the array is multi-dimensional, returns the list of the indexes of every dimension. If the array contains objects rather than scalar values, the class these objects inherit from must own a defined comparison operator <. If not, this class must otherwise define at least one char, string, integer or float casting operator or the hash operator #. If many are defined, priority for the casting before comparision will be hash first and char last, in the inverse order of previous list. If no such operator is defined, an error will occur at translation time.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 7] ];
print( the_array.argmax() );     // prints: [0,0] - the index of first found 8
print( the_array[1].argmax() );  // prints: 0
const list argsmax()

Returns the index of all maximal values found in an array. If the array is multi-dimensional, returns the list of the indexes of every dimension. If the array contains objects rather than scalar values, the class these objects inherit from must own a defined comparison operator <. If not, this class must otherwise define at least one char, string, integer or float casting operator or the hash operator #. If many are defined, priority for the casting before comparision will be hash first and char last, in the inverse order of previous list. If no such operator is defined, an error will occur at translation time.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 7] ];
print( the_array.argsmax() );     // prints: [[0,0], [1,0]]
print( the_array[0].argsmax() );  // prints: [0]
const float64 mean()

Evaluates the mean over the whole array. Arrays have to contain either integer or float values. Such values may be obtained via integer or float casting operators defined in classes from which inherit the objects that are contained in the array. When cast operators exist, the related casting will be silently applied by Typee translators. If many casting operators are defined, the largest floating one will be first and if none is defined, the largest integer one will be applied.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 7] ];
print( the_array.mean() );     // prints: 4.375
print( the_array[// prints: 4.75
const float64 stdev()

Evaluates the standard deviation over the whole array. Arrays have to contain either integer or float values. Such values may be obtained via integer or float casting operators defined in classes from which inherit the objects that are contained in the array. When cast operators exist, the related casting will be silently applied by Typee translators. If many casting operators are defined, the largest floating one will be first and if none is defined, the largest integer one will be applied.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 7] ];
print( the_array.stdev() );     // prints: 3.1594529
print( the_array[0].stdev() );  // prints: 2.5
const float64 median()

Evaluates the median value over the whole array. The computed value may not belong to the array – see median_low() and median-high() to get median value belonging to the array.
Arrays have to contain either integer or float values. Such values may be obtained via integer or float casting operators defined in classes from which inherit the objects that are contained in the array. When cast operators exist, the related casting will be silently applied by Typee translators. If many casting operators are defined, the largest floating one will be first and if none is defined, the largest integer one will be applied.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 7] ];
print( the_array.median() );     // prints: 4.5
print( the_array[1].median() );  // prints: 4.0
const ? medianlow()

Evaluates the median value over the whole array. The computed value is forced to belong to the array and is the highest contained value that is less than the true median value – see example below.
Arrays have to contain either integer or float values. Such values may be obtained via integer or float casting operators defined in classes from which inherit the objects that are contained in the array. When cast operators exist, the related casting will be silently applied by Typee translators. If many casting operators are defined, the largest floating one will be applied first and if none is defined, the largest integer one will be applied.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 7] ];
print( the_array.medianlow() );     // prints: 4
print( the_array[1].medianlow() );  // prints: 1
const ? medianhigh()

Evaluates the median value over the whole array. The computed value is forced to belong to the array and is the lowest contained value that is greater than the true median value – see example below.
Arrays have to contain either integer or float values. Such values may be obtained via integer or float casting operators defined in classes from which inherit the objects that are contained in the array. When cast operators exist, the related casting will be silently applied by Typee translators. If many casting operators are defined, the largest floating one will be applied first and if none is defined, the largest integer one will be applied.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 7] ];
print( the_array.medianhigh() );     // prints: 5
print( the_array[1].medianhigh() );  // prints: 7
const ? in (uint32, list) argmedianlow()

Returns the index of the first value found in an array that is the greatest of all values that are lower than the true median value – see example below.
Arrays have to contain either integer or float values. Such values may be obtained via integer or float casting operators defined in classes from which inherit the objects that are contained in the array. When cast operators exist, the related casting will be silently applied by Typee translators. If many casting operators are defined, the largest floating one will be applied first and if none is defined, the largest integer one will be applied.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 7] ];
print( the_array.argmedianlow() );     // prints: [0,1]
print( the_array[1].argmedianlow() );  // prints: 2
const list argsmedianlow()

Returns the indexes of all values found in an array that are the greatest of all values that are lower than the true median value – see example below.
Arrays have to contain either integer or float values. Such values may be obtained via integer or float casting operators defined in classes from which inherit the objects that are contained in the array. When cast operators exist, the related casting will be silently applied by Typee translators. If many casting operators are defined, the largest floating one will be applied first and if none is defined, the largest integer one will be applied.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 4, 7] ];
print( the_array.argsmedianlow() );     // prints: [[0,1], [1,2]]
print( the_array[1].argsmedianlow() );  // prints: [2]
const ? in (uint32, list) argmedianhigh()

Returns the index of the first value found in an array that is the lowest of all values that are greater than the true median value – see example below.
Arrays have to contain either integer or float values. Such values may be obtained via integer or float casting operators defined in classes from which inherit the objects that are contained in the array. When cast operators exist, the related casting will be silently applied by Typee translators. If many casting operators are defined, the largest floating one will be applied first and if none is defined, the largest integer one will be applied.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 7] ];
print( the_array.argmedianhigh() );     // prints: [0,2]
print( the_array[1].argmedianhigh() );  // prints: 3
const list argsmedianhigh()

Returns the indexes of all values found in an array that is the lowest of all values that are greater than the true median value – see example below.
Arrays have to contain either integer or float values. Such values may be obtained via integer or float casting operators defined in classes from which inherit the objects that are contained in the array. When cast operators exist, the related casting will be silently applied by Typee translators. If many casting operators are defined, the largest floating one will be applied first and if none is defined, the largest integer one will be applied.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 5] ];
print( the_array.argsmedianhigh() );     // prints: [[0,2], [1,3]
print( the_array[1].argsmedianhigh() );  // prints: [3]
4.1.4.7 Array dimensions

Number of dimensions and their sizes can be accessed these ways:

const uint64 dims_nb()

Returns the number of dimensions of an array.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 5] ];
print( the_array.dims_nb() );     // prints: 2
const list dims_sizes()

Returns the sizes of all dimensions of an array, the most external dimension first and the most internal dimension last.
Example:

array<uint8>[][] the_array = [ [8, 4, 5, 2], [8, 0, 1, 5] ];
print( the_array.dims_sizes() );     // prints: [2, 4]

4.1.5 Arrays as arguments

Functions and methods signatures are constituted of the types of their arguments and the type of value they return. Arrays may be passed as arguments to functions and methods and may be passed back to caller on return. Keyword array is a generic type to specify any kind of array, whatever its dimensions, its size and the maybe declared types for its content.
When dealing with an array argument in functions and methods, the dimensions number and sizes of this array can be retrieved with the dedicated built-in functions dims_nb() and dims_sizes() – see previous sub-section on Array dimensions.

Next section formerly explains built-in lists.

< previous (4. bultin-containers) | (4.2 built-in lists) next >