Larry Wall larry-at-wall.org |Perl 6| wrote:
Now, you'll ask how *-2 works. If you do math on a Whatever object,
it just remembers that offset until the Whatever is given a meaning,
which, in this case, is delayed until the subscripting operator
decides what the size of the next dimension is. At a lower level than
the subscript it probably ends up being some kind of a fallback
multi that binds to a Whatever type for that dimension, as the
subscripting operator processes through each dimension in its @@ array.
Or maybe it's just a case in a switch. In any case, the subscriptor
knows the next "top" dimension, so it can know the size at that point.
I see. The *-2 isn't resolved to a number right away, but evaluates to
a "whatever-2" object, that is passed. The subscripting implementation
knows what is going on when it gets to that.
That means that ordinary uses will not require knowledge about the
dimensions and context, as it is handled all inside the subscripting code.
But constructs that generate loops around that expression will have to
know. This certainly includes the autoindexing thing being discussed in
another thread. But I'm also thinking of junctions. Junctions thread
through the subscript, it is writ. A junction, like a range, can use *
for an endpoint, can it not?
Writing @foo[$x;2..*;$y] >>*<< blah blah
will serve up the slice first, using the mechanism described above. But
the similar
$n=all(2..*); @foo[$x;$n;$y] * blah blah
is described as creating a loop around the * operator. I guess it would
convert to the first one and see what the subscripter gave back? Is
that still possible if multiple junctions are present?
--John