It is a common problem in programming to need a list of things and to be able to handle each member of a list the same way and to process the entire list. It would be possible to designate variables a1, a2, a3 but there is no way to manage them in that. Hence we introduce the idea of an array.
First you declare the names of the variables that you want to be arrays with an expression like:
array x, $y, @z
This tells script that there is an array of integers called x, an array of strings called y and an array of floating point numbers called z. You can define as lots of arrays and use any name that would be legal for a variable. However if you now try to use x=5 it will say syntax error as x is a list of variables and you must specify which one. x[0]=5 sets the first member of the list to 5 and x[1]=8 the second member of the list to 8. Similarly $y[7]="eighth" and @z[4]=3.14 set the members of their lists. The value in the square brackets is called the subscript and will be evaluated as an integer.
You can use array members in any mathematics that you could use a normal variable and you can use a variable or an expression for the index. We currently limit the maximum number of elements in an array to 1024. If you try to use an element below zero or above 1023 the program will fail when running with a message Out of range array subscript. Elements that have not been assigned values are zero or strings with no characters in them.
Arrays are probably at their most useful when the index is a variable and some process loops through all the elements.
We provide some functions that specifically act on arrays.
clear(array) resets all the values to zero or an empty string as appropriate.
elements(array) returns the size of the array being the highest index of a non-null value+1.
chars("abcdef", array) puts 97 (the value of 'a') into array[0], 98 ('b') into array[1] etc. It will return a value of 6 representing the number of characters transferred. The array is cleared before the transfer.
$chars(array) reverses the process returning a string made from the values in the array. Remember that a zero terminates a string in all cases.
Multi-dimensional arrays
You can define an array with multiple dimensions by using a definition like array 2 $status and then access the elements as $status[0][0] etc. Currently we limit this to 5 dimensions as memory requirements rapidly escalate beyond simple management.
clear() works on a multi-dimensional array.
elements(n) for dimensions greater than 1 returns the working array size on the nth dimension (counting from 0) which might be greater than the index of the highest non-zero element but will not be less.
chars() and $chars() do not work on multi-dimensional arrays.
Passing multi-dimensional arrays into user functions is not supported.
Arrays and the Debugger
When using the debugger the elements are displayed with their indexes
However, to try and conserve space, the elements that are integers and floating point numbers that contain zero and the strings that contain no characters are not displayed in the debugger.