From S09:
"When you use * with + and -, it creates a value of Whatever but Num,
which the array subscript interpreter will interpret as the subscript
one off the end of that dimension of the array."

"Alternately, *+0 is the first element, and the subscript dwims from
the front or back depending on the sign. That would be more
symmetrical, but makes the idea of * in a subscript a little more
distant from the notion of 'all the keys', which would be a loss, and
potentially makes +* not mean the number of keys."

If '*+0' isn't the first element, then '*+$x' is only meaningful if $x < 0.

That said, I think I can do one better:

Ditch all of the above.  Instead, '*' always acts like a list of all
valid indices when used in the context of postcircumfix:<[ ]>.

If you want the last index, say '*[-1]' instead of '* - 1'.
If you want the first index, say '*[0]' instead of '* + 0'.

So the four corners of a two-dimensional array would be:

 @array[ *[0]; *[0] ];  @array[ *[-1]; *[0] ];
 @array[ *[0]; *[-1] ]; @array[ *[-1]; *[-1] ];

The only thing lost here is that '@array[+*]' is unlikely to point
just past the end of a shaped array.  But then, one of the points of
shaped arrays is that if you point at an invalid index, you get a
complaint; so I don't see why one would want to knowingly point to
one.

--

Also, has the syntax for accessing an array's shape been determined
yet?  If not, I'd like to propose the following:

@array.shape returns a list of lists, with the top-level list's
indices corresponding to the dimensions of the shape and each nested
list containing every valid index in that dimension.  In boolean
context, the shape method returns true if the array is shaped and
false if not - though an unshaped array will otherwise pretend to be a
one-dimensional, zero-based, non-sparse, shaped array.

So:

 @array.shape[0][2] # the third valid index of the first dimension of the shape
 @array.shape[-1][0] # the first valid index of the last dimension of the shape
 @array.shape[1] # every valid index of the second dimension of the shape
 @array.shape[1][*] # same as @array.shape[1]

 [EMAIL PROTECTED] # is this a shaped array?

 exists @array.shape[2] # does the array have a third dimension?
 exists @array.shape[3][4] # does the fourth dimension have a fifth element?

 [EMAIL PROTECTED] # how many dimensions does the shape have?
 [EMAIL PROTECTED] # how many indices does the first dimension have?

If we use this notation, then

 @array[ *; * ]

is shorthand for

 @array[ @array.shape[0]; @array.shape[1] ]

--
Jonathan "Dataweaver" Lang

Reply via email to