[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Dec 23 09:11:55 2002 
Subject:Re: Syntax Help: init array from procedure (please) 
From:steve 
Volume-ID:1021223.01 

Hi,

It isn't obvious to me how I should rely to Lee Goddard.  Either 
someone could forward this or point out what I am missing!

Lee writes:
>Anyway, the third in the series has this:
>
>     vars gmask_2d;
>     newarray([% -gsize, gsize, -gsize, gsize %],
>         procedure(x, y); lvars x, y;
>             gmask(x) * gmask(y)
>         endprocedure) -> gmask_2d;
>
>Aside from the wonder of negative-indexed arrays, could someone
>please explain to me what is going on with this?

In Pop11 (and other programming languages) arrays are given "bounds" 
when they are built.  Each dimension of the array is bound by a first 
and last index.  The first index tells the array what the origin of 
that dimension is.  Negative origins are very common in scientific 
programming where distributions are often balanced around zero.


>  It seems to
>be that that gmask_2d array is initialised with the values of
>the procedure(x,y), but I can't understand where (x,y) come from.
>
>Is it a feature of the language that they will be supplied by
>the interpreter as the array is initialised?

Yes, this is roughly correct.  The "newarray" procedure is 
responsible for both constructing the array store (from the 
boundslist supplied) and initializing the store.

The main way "newarray" expects to be told how to initialize the 
store is by being passed a procedure.  And this is the case in your 
example.  The procedure should take N arguments where N is the number 
of dimensions of the array.  It is expected to return a single 
result.  As you might expect, the "newarray" procedure then invokes 
this procedure on all possible indexes of the array and stores the 
results.

So the (x,y) are generated by "newarray".  This is an essential 
feature of array construction in Pop-11.

-- 
Steve