How is @array[*-2] supposed to be implemented?

// 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?

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!

In any case, there should be "ordinary" methods that do the same thing, and * magic is documented as calling them. Perhaps @array.user_defined_index($dimenstion)<May> .

If creating your own object that has the Positional role, these member functions need to be provided. Or, to do strange things, you may derive from Array and alter these functions, or wrap them, or whatever. Point is, you need to know that these functions are being called to support the special * syntax.

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


Reply via email to