Yazoo ---> Online Help Docs ---> Yazoo scripting ---> Arrays

Resizing

All arrays in Yazoo that are not `jammed' may be resized, and there are a number of ways to accomplish this. The most straightforward method is to use the modified index operator [^...] which sets the maximum index of a single dimension of the array. This can be used to either increase or reduce the size of the array, and several of these operators can act simultaneously on their respective indices in a given expression. The resize operator is similar to [*] in that it returns the full range of that index of the array; however, unlike [*] it does not return anything unless it is embedded in a larger expression (so in the case of print(a[^5]) no token is created for a[] and so nothing is printed).

Indices may also be inserted into the middle of an array, using the [+...] and +[...] operators. (There is a subtle difference between the two which is only important in the rare case of an array with multiple members--a situation that is considered at the end of this section.) New indices are inserted into the array at the position specified in brackets before subsequent operations are performed. These operations return the new chunk of the array only, although as in the case of [^...] no token is created if an insertion operator begins a sentence.

The delete command nixes array indices in the same way that [+...] creates them. The syntax is slightly different: delete my_array[2, 3] is an example. Be careful not to confuse delete with remove! The former deletes the actual storage of variables whereas the latter removes members, which does not a-priori affect the content of variables (though Yazoo will eventually clean out variables that have no members to access them by). The delete command cannot be used within a larger expression, and it does not return a value under any circumstances, since after it has done its work there is hopefully nothing left to send back.

Let us suppose that we have an array which we have defined as `a[2][3] :: ...'. We can alter it in the following ways to illustrate use of the resize operators.


    > sprint(a)
   
    { { 11, 12, 13 }, { 21, 22, 23 } }
   
    > a[+2], sprint(a)
   
    { { 11, 12, 13 }, { 0, 0, 0 }, { 21, 22, 23 } }
   
    > delete a[*][2], sprint(a)
   
    { { 11, 13 }, { 0, 0 }, { 21, 23 } }
   
    > a[*][^5], sprint(a)
   
    { { 11, 13, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 21, 23, 0, 0, 0 } }
   

Notice that newly-allocated memory is always initialized to zero.

One final way to resize an array is to do so implicitly through the wildcard [*] operator. If an equate or forced-equate statement is prevented from copying data because of mismatched array sizes, and if there is a wildcard index in the destination variable (i.e. to the left of the equate; Yazoo will never alter the source variable to the right), then Yazoo will see if it can resize the array to allow the data to be copied. Since the specifying of an index range unrolls the table into a list, Yazoo does not care whether the indices of the source and destination are individually matched: a[1, 3][*] = b[1, 6] is perfectly legal. For equate, the total number of indices must be equal, and in the previous example the second index will resize to 2. A forced-equate will attempt to make the total size in bytes of the two sides equal, if necessary.


Prev: Arrays   Next: Aliasing and jamming


Last update: July 28, 2013

Get Yazoo scripting language at SourceForge.net. Fast, secure and Free Open Source software downloads