Hmm, both of you are kinda going off on a tangent here.  The meaning of
the Whatever represented by * is neither something that gets magically
interpreted before postcircumfix:<[ ]>, nor is it a compile-time
rewrite.  Context is supplied by binding in Perl 6, and the binding
happens within .[].  It's the fact that the parameter within .[]
is declared with @@ that causes it to bind as a slice, so that each
dimension of the argument comes in as a single array element.

(By the way, you'll note the utility of being able to talk about a
postfix by saying .[], which is one of the reasons we allow the optional
dot there. :)

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.

At compile time the subscript parser really only knows how
many dimensions are referred to by how many semicolons there
are.  A subscript that is explicitly cast to @@ is known to be
multidimensional, and interpolates the returned List of Capture into
the outer List of Capture, and the compiler can make no compile-time
assumptions about how far down the dimension list any subsequent
dimensional sublists will end up.

However, at least we can hope that @@ x() specifies the exact number
of dimensions to interpolate at run time.

One additional variant of Whatever is **, which represents an
arbitrary number of dimensions.  In essence, it's an instruction
to the subscripting logic as it's processing top-down through the
dimensions that it has to reverse its logic and count the rest of
the subscripts bottom-up from the end of its @@ bound list instead
of from the beginning.  As such, there can really only be one such
reversal, so we limit ourselves to a single ** argument representing
an arbitrary number of dimensions to skip over, assuming the rest
of the dimensions are end-anchored, as it were.

Larry

Reply via email to