Search                        Top                                  Index
HELP NEWARRAY                      updated Mark Rubinstein  October 1985
                                                    A. Sloman April 1989

See HELP * ARRAYS for an introduction to arrays in POP-11.

    newarrary(<boundslist>) -> <array>
    newarrary(<boundslist>, <initial value>) -> <array>
    newarrary(<boundslist>, <initialising procedure>) -> <array>

The simplest way to create an array in POP-11 is to use NEWARRAY, which
creates an array capable of holding any POPLOG data-types.

    newarray(<boundslist>, <initial value>) -> <array>

E.g.
    newarray([1 5 1 10], 0) -> aa;

creates a two dimensional 5 by 10 array each of whose elements is 0.
The elements of the array are accessed or updated using two integers
the first in the range 1 to 5, the second in the range 1 to 10, as
specified in the <boundslist> argument. The syntax used is the same as
if the array were a procedure (which in fact it is in POP-11). So:
    aa(3,5) =>
    ** 0

    66 -> aa(3,5);
    aa(3,5) =>
    ** 66

    [a list ] -> aa(4,2);
    aa(4,2) =>
    ** [a list]

NB: the second argument of NEWARRAY mus not be a list as it will
then be taken to be the <boundslist>. See the use of initialising
procedures below.

If the second argument is missing, it defaults to the word "undef".

    newarray([1 10 1 10]) -> aa;

This creates a ten by ten array, both of whose subscripts vary in the
range one to ten, all the elements being undef. (See HELP *UNDEF)
    aa(5,5) =>
    ** undef

    newarray([-5 15])

Creates a one dimensional array whose subscript varies in the range
-5 to 15.

Instead of an initial value, the second argument to NEWARRAY may be a
procedure which computes the value on the basis of the subscripts. The
procedure must take as many arguments as the dimensions of the arrary.
Thus, to create a 3 by 5 array whose elements are the product of the
susbcripts do:
    newarray([1 3 1 5], nonop *) -> aa;

Then:
    aa(2,5) =>
    ** 10
    aa(3,2) =>
    ** 6

Or to create an array containing a list of the subscripts:
    newarray([-5 5 -10 10], procedure(x,y); [^x ^y] endprocedure) -> aa;

    aa(-3,5) =>
    ** [-3 5]

There is a more powerful procedure *NEWANYARRAY that can be used to
create 'packed' arrays corresponding to any vector data-type, e.g. it
could create a compact array of bits, or of 4 bit integers. NEWARRAY
coudl have been defined in terms of it thus:

    vars newarray;
    newanyarray(%initv, subscrv%) -> newarray;

See HELP * NEWANYARRAY for details on setting up initial component values.
See
REF * DATA          - POP-11 data types and accessing procedures
REF * KEYS          - data keys associated with a data class
REF * VECTORS       - VECTOR types in POP-11
HELP * VECTORCLASS  - Defining new vector types
HELP * CLASSES      - classes and procedures associated with a class
See also HELP * BOUNDSLIST, *ARRAYVECTOR, *ISARRAY

--- C.all/help/newarray
--- Copyright University of Sussex 1989. All rights reserved. ----------