On Fri, Aug 8, 2008 at 7:41 PM, John M. Dlugosz
<[EMAIL PROTECTED]> wrote:
> How is @array[*-2] supposed to be implemented?
>
> S09<v28>
> // reported again 8-Aug-2008
>
> Is this magic known to the parser at a low level, or is it possible to
> define your own postcircumfix operators that interact with the
> interpretation of the argument?

IMHO, this can best be answered by the implementors: it depends on how
difficult it would be to enable user-defined code.  My own bias would
be toward the latter; but I'm not an implementor.

> Does this use of * apply to any user-defined postcurcumfix:<[ ]> or just
> those defining the function for the Positional role, or what?  And whether
> or not it always works or is particular to the built-in Array class, we need
> to define preciely what the * calls on the object, because I<those> may be
> overridden. For example, it is obvious that a lone * in an expression calls
> .length.  But the *{$idx} and *[$idx] work by calling some method on the
> Array object, right?  Something like @array.user_defined_index<May> to
> discover that May maps to 5, or @array.user_defined_index[5] to produce May.
>  That is, the accessor .user_defined_index() returns an object that supports
> [] and {} just like an Array.  It may or might not be an Array populated
> with the inverse mappings. But it behaves that way.
>
> But that doesn't work for multidimensional arrays.  The meaning of *{} is
> dependent on its position in the list.  This means that it must be able to
> count the semicolons!  If the slice is composed at runtime, it needs to
> operate at runtime as well, and this implies that the called function is
> told which dimension it is operating upon!

This is also true when using a lone * in an expression: the number of
elements that it represents depends on which dimension it appears in.
As well, a similar point applies to **.

IIRC, there's supposed to be a 'shape' method that provides
introspection on the index.  Exactly what it's capable of and how it
works has not been established AFAIK.

> Is it possible to write:
>        @i = (1, 3, *-1);
>        say @data[$i];
> and get the same meaning as
>        say @data[1, 3, *-1]?

I believe so.  IIRC, evaluation of * is lazy; it gets postponed until
there's enough context to establish what its meaning is supposed to
be.

-- 
Jonathan "Dataweaver" Lang

Reply via email to