Daniel Ruoso daniel-at-ruoso.com |Perl 6| wrote:
So, how do I deal with a multidim array? Well, TIMTOWTDI...

 my @a = 1,[2,[3,4]];
 say @a[1][1][1];
 say @a[1;1;1]; # I'm not sure this is correct

I think that it should be. That is, multi-dim subscript is always the same as chained subscripts, regardless of whether the morphology is an array stored as an element, or a multi-dim container, or any mixture of that as you drill through them.

I've not written out a full formalism yet, but I've thought about it.
The multi-dim subscript would return a sub-array if there were fewer parameters than dimensions, an element if exact match, and recursively apply the remaining subscripts to the element if too many.


Or.. (I'm using the proposed capture sigil here, which has '@%a' as its
expanded form)

 my ¢a = 1,(2,(3,4);
 say ¢a[1][1][1];
 say ¢a[1;1;1];

I think that makes the semantics of the API more clear...

daniel


The plain Array would work too, in the nested morphology:

   my @a = 1,[2,[3,4]];

@a has 2 elements, the second of which is type Array.

   say @a[1][1][1];

naturally.

   say @a[1;1;1];

means the same thing, intentionally.

   say @a[1][1;1];
   say @a[1;1][1];

ditto.

--John


Reply via email to