Arrays

Accessing elements of an array
one dimension
two dimension
three dimension
member of structure that is an element of an array of structures
element of an array that is a member of a structure
Determining the number of elements in an array
Determining the number of dimensions in an array
Multiple references to the same array
Sub-array (row slice)
Assigning runtime space for arrays
Changing the size of an array
Creating an array
Creating copies of arrays
Creating sparse arrays
Creating an array of structures

Accessing elements of an array

a[x] element of a 1 dimensional array
a[x, y] element of a 2 dimensional array
a[x][y] element of a 2 dimensional array
a[x, y, z] element of a 3 dimensional array
a[x][y][z] element of a 3 dimensional array
a[x] . b member of structure that is an element of an array of structures
a . b[x] element of an array that is a member of a structure

determining the number of elements in an array

	array_length(arr)

determining the number of dimensions in an array

	dim_cnt(arr)

Multiple references to the same array

This is equivalent to a 'C' pointer to array.

	arr1 = ref(arr)
	arr2 = ref(arr1)
To access an element of a shared array (array with multiple references) use the  '['  ']'   operators in exactly the same way as for a non-shared array.

To obtain a uniqe copy of a shared array use the 'value' function. However beware that an array that has an embedded reference to itself cannot be completely copied as it will still have references to the original array embedded in it.

e.g.

	arr3 = value(arr2)

Sub-array (row slice)

sub-sections of a multi-dimensional array can be accessed by reference.

A two dimensional array can be accessed as multiple one dimensional arrays where each new one dimensional array is actually a row of the original array.

e.g.

	M_arr = array(3, 5)

	arr0 = ref(M_arr[0])
	arr1 = ref(M_arr[1])
	arr2 = ref(M_arr[2])

	arr1[3] is equivalent to M_arr[1,3]
this allows more efficient array access mechanisms to used when performing complex operations on multi-dimensional arrays.

e.g.


	M_arr = array(3, 5)

	acc = 0;

	for j=0 while j<3 step j+=1 do

		S_arr = ref(M_arr[j])

		for k=0 while k<5 step k+=1 do
			acc += S_arr[k]
		done
	done

Assigning runtime space for arrays

creating an array
	arr = array(n)
	arr = array(n, m)
	arr = array(n, m, o, p, q)

creating copies of arrays

	arr2 = arr

changing the size of an array

	arr2 = extend_array(arr1, x)

creating sparse arrays

	arr = array(3)
	arr[0] = array(5)
	arr[1] = array(10)
	arr[2] = array(15)

Accessing the elements of this sparse array is exactly the same as accessing the elements of a regular multidimensional array

creating an array of structures

	tmp = struct()
	tmp.a = 0
	tmp.b = 0
	tmp.c = 0

	arr = array(10)

	for j=0 while j<10 step j+=1 do
		arr[j]  = tmp
	done

see also

external interface to arrays