arrays |
Discworld efun help |
arrays |
There is support for arrays. The arrays can't be declared, but should be allocated dynamically with the function 'allocate()' (see allocate).
Arrays are stored by reference, so all assignments of whole arrays will just copy the address. The array will be deallocated when no variable points to it any longer.
When a variable points to an array, items can be accessed with indexing: 'arr[3]' as an example. The name of the array being indexed can be any expression, even a function call: 'func()[2]'. It can also be another array, if this array has pointers to arrays:
arr = allocate(2);
arr[0] = allocate(3);
arr[1] = allocate(3);
Now 'arr[1][2]' is a valid value.
The 'sizeof()' function (in true C, not a function) will give the number of elements in an array (see sizeof).
ARRAY CONSTRUCTOR
Arrays can be constructed with a list inside '({' and '})'. Example: ({ 1, "xx", 2 }) will be construct a new array with size 3, initialized with 1, "xx" and 2 respectively.