2.7 Dimension Lists
You should strive to write Yorick programs in such a way that you never need to refer to the lengths of array dimensions. Array dimensions are usually of no direct significance in a calculation; your programs will tend to be clearer if only the arrays themselves appear.
In practice, unfortunately, you can't always get by without mentioning dimension lengths. Two functions are important:
The array function (see section 2.1 Creating Arrays), and the more arcane functions add_variable, add_member, and reshape all have parameter lists ending with one or more "dimension list" parameters. Each parameter in a dimension list can be either a scalar integer value, representing the length of a single dimension, or a list of integers in the format returned by dimsof to represent zero or more dimensions. Several arguments can be used to build up a complicated dimension list:
In the final example, the flux might represent the three components of a flux vector, at each of a number of positions z, and for each of a number of photon energies groups. The first dimension of flux has length three, corresponding to the three components of each flux vector. The last dimension has the same length as the groups array. In between are zero or more dimensions -- whatever the dimensions of the array of positions z.
By using the rubber index syntax (see section 2.3.7 Using a rubber index), you can extract meaningful slices of the flux array without ever needing to know how many dimensions z had, let alone their lengths.