Daniel (>>), Stefan (>):
>> 1. The semicolon operator would allow Perl 6 to support N-dimensional
>> arrays... How would one iterate over that type of array?
>>
>> my num @matrix[ 10 ; 10 ; 10 ];
>>
>> I ask because a natural extension is to add arithmetic operators and
>> you have the beginnings of a Matlab-like array language.
>
> I've started trying to implement S09 things this month, and this is
> actually one of the big questions that came up for me.  I raised it
> on IRC earlier (which is much more active than p6l, fwiw) and I don't
> think we actually arrived at a definite answer.
>
> There are three obvious choices for what 'for @matrix { }' means:
>
> * Iterate over slices that fix the leftmost index
>
> * Iterate over all elements in lexicographic order
>
> * Die
>
> I'm currently thinking of the first, because it allows
> (map {$_}, @matrix)[0] to mean the same thing as @matrix[0].  But it's
> likely there are other nice considerations.

My vote also falls on alternative (1). S09 already has wording on
indexing being "the same" for shaped arrays and nested arrays:

    For all multidimensional array types, it is expected that cascaded
subscripts:

        @x[0][1][42]
        @x[0..10][1,0][1,*+2...*]

    will either fail or produce the same results as the equivalent
    semicolon subscripts:

        @x[0;1;42]
        @x[0..10; 1,0; 1,*+2...*]

We could extrapolate this to give support for alternative (1).

Also, though my memory may be playing tricks on me here, I believe it
is consistent with what APL does.

>> 2. Do you think Rakudo is likely to get support for N-dimensional
>> arrays in... say... the next year or so?
>
> No comment.  If pmichaud stays alive and well, anything is possible.

The "shaped arrays/hashes" parts of S09 have been in the planning
stages a long time in Rakudo. They've had to wait for better MOP and
better native-types handling (which is another part of S09), but now
the time for shaped arrays/hashes is surely here. If jnthn or pmichaud
hasn't started digging into them by the time I finish the macro grant,
I likely will.

We know shaped arrays/hashes are a slightly murky area in the spec.
It's not as bad as, say, S16 (I/O) or S17 (concurrency), but it's
probably slightly inconsistent simply due to its sheer ambitiousness.
Part of what hinders its imminent implementation is that anyone who
picks it up will have to ask piercing questions such as the above one
for quite a while, then form a mental model of what needs to be
implemented, then implement it. After that has happened, we'll look at
S09 and throw out a bunch of things that proved to be simplistic,
naive, or plain wrong.

Still, I look forward to those parts being implemented. In some vague
sense, shaped arrays/hashes are "just" sugar, but I believe they'll
form an integral part in "idiomatic Perl 6", and provide a real edge
over corresponding unsugared Perl 5 code, even in fairly simple
scripts.

// Carl

Reply via email to