An array in Pop-11 is something like a vector of vectors, or a list of lists. For example, suppose you wished to create a 3 by 4 array for later use to store information.
You could do this:
vars vecarray =
{ {undef undef undef}
{undef undef undef}
{undef undef undef}
{undef undef undef}};
vecarray ==>
** {{undef undef undef}
{undef undef undef}
{undef undef undef}
{undef undef undef}}
(Note that "undef" is a word that is provided in Pop-11 for use when a
structure has to contain elements that are not yet defined.) We can
store the word "cat" in the third field of the second vector thus:
"cat" -> vecarray(2)(3);
vecarray ==>
** {{undef undef undef}
{undef undef cat}
{undef undef undef}
{undef undef undef}}
or access it thus:
vecarray(2)(3) =>
** cat
Then we can access or update any element of this structure by giving it
two numbers, the first between 1 and 4, and the second between 1 and 3.
This is in effect a two dimensional array with bounds 1 and 4 in the
first dimension and bounds 1 and 3 in the second dimension.
However, Pop-11 provides a mechanism for creating entities called arrays which can have any number of dimensions and whose bounds can be any integers, positive or negative. So we can create a 3D array with bounds 2 to 5, 3 to 10, and -5 to +5 thus:
vars array3d = newarray([2 5 3 10 -5 5]);To access its elements we can give it three numbers, one for each dimension, e.g.
array3d(3, 4, -4) =>
** undef
Initially the word "undef" is the value of each field. We can update it
thus:
[a list] -> array3d(3, 4, -4);then
array3d(3, 4, -4) =>
** [a list]
This shows that just as a vector or list can be treated as a procedure
applicable to one number at a time, to get at a particular location, so
an N-dimensional array is an object that can be treated as a procedure
that is applicable to N integers to access or update a field in the
array.
Because arrays in Pop-11 are treated as procedures, all the operations available on procedures can be used with them, including partial application. Thus if you can partially apply array3d to the number -4, to produce what is effectively a 2d array, which corresponds to one 2-d "plane" in array3d, thus:
vars array2d = array3d(% -4 %);
array2d(3, 4) =>
** [a list]
Again this ability in Pop-11 to abstract from the differences between
arrays and real procedures and treat them all as procedures provides
powerful facilities for generalisation and re-use of the same mechanisms
in different contexts.
More will be said on arrays in a later chapter.