- 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
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 doneAssigning runtime space for arrays
creating an arrayarr = array(n) arr = array(n, m) arr = array(n, m, o, p, q)arr2 = arrarr2 = extend_array(arr1, x)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 donesee also
external interface to arrays