Exception Handling categories
Lists, Sets and Instructions
array
Methods and Types
Methods

array

An array can be seen as a fixed-size list, with a member type (the slot name is of), which tells the type of all the members of the array. Because of the fixed size, the compiler is able to generate faster code than when using lists, so lists should be used when the collection shrinks and grows, and an array may be used otherwise. This is especially true for arrays of floats, which are handled in a special (and efficient) way by the compiler.

Arrays are simpler than lists, and only a few operations are supported. Therefore, more complex operations such as append often require a cast to list (list!). An array is created explicitly with the make_array property :
 let l := make_array(10,float,0.0)
 in l[1:= l[3+ l[4]
Operations on arrays include copying, casting a bag into an array (array!), defeasible update on arrays using store, and returning the length of the array with length. An array can also be made from a list using array!, which is necessary to create arrays that contain complex objects (such as arrays of arrays).


categories arraynormal dispatch Kernel method

array!(x:bag, t:type) -> type[t[]]

creates a copy of the bag x that is represented as an array. The member type must be given as a parameter t and an error will occur if a member of the bag does not belong to t..


categories arraynormal dispatch Kernel method

copy(a:array) -> array

The copy of an array returns a fresh array with the same elements


categories arraynormal dispatch Kernel method

get(a:array, x:any) -> integer

get(a, x) returns the lowest i such that a[i] = x (if no such i exists, 0 is returned).


categories arraynormal dispatch Kernel method

length(a:array) -> integer

returns the length of an array


categories arraynormal dispatch Kernel method

list!(a:array) -> type[list[member(a)]]

list!(a) transforms a into a list.


categories arraynormal dispatch Core method

make_array(i:integer, t:type, v:any) -> type[(if unique?(t) the(t)[] else array)]

returns an array of length n filled with x. The parameter t is the member_type of the array, thus x must belong to t, as well as any future value that will be put in the array.


categories arraynormal dispatch Kernel method

Kernel/member_type(x:array) -> type

member_type(x) returns the type of all members of the array x. Therefore, member(a) = member_type(a) for an array a.


categories arrayinline Kernel method

nth(a:array, i:integer) => any

nth(a,i) returns the ithelement of the array a. nth(a,i) is equivalent to a[i].


categories arraynormal dispatch Kernel method

nth=(self:array, x:integer, y:any) -> void

nth=(a,i,x) replace the ithelement of the array a by x. nth(a,i,x) is equivalent to a[i] := x.