Syntax Help: init array from procedure (please) 
Author Message
 Syntax Help: init array from procedure (please)

Hello there,

Been a while since I read any POP-11, and don't have a copy
of the language at hand, but am working throught the Sussex
TEACHVISION files in Perl ....

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?  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?

Any help much appreciated
lee



Thu, 09 Jun 2005 18:43:43 GMT  
 Syntax Help: init array from procedure (please)
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!

Quote:
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.

Quote:
>  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



Fri, 10 Jun 2005 17:11:55 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. help please-----please help about array in DLL

2. array-valued procedure: I/O reccursion with module procedure

3. Creating INIT PROCEDURE in ASM/C ?

4. help with array syntax for a loop

5. please, please, please, please, help

6. Can u please help in a scheme procedure?

7. Please Help: Syntax for reading from a file.

8. will someone please, please, please, please HELP me?!!

9. SQL Syntax errors, please help

10. Please help (syntax problems?)

11. Help PLease..Tcl/Expect - C program generates an expect procedure

12. Help: Returning an array from a procedure...

 

 
Powered by phpBB® Forum Software