Larry Wall wrote:
On Fri, Feb 23, 2007 at 10:49:34AM -0800, Jonathan Lang wrote:
: 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:<[ ]>.

Ooh, shiny!  Or at least, shiny on the shiny side...

Thank you...

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

So the generic version of leaving off both ends would be *[1]..*[-2]
(ignoring that we'd probably write *[0]^..^*[-1] for that instead).

Correct - although that assumes that the indices are consecutive (as
opposed to, say, 1, 2, 4, 8, 16...); this version of * makes no such
assumption.

I do find myself wondering what *[-1] would be for an infinite array,
such as @nums[0..*:by(2)].

One possible answer: Inf.

Another possible answer: the shape sets limits on the indices; it does
not set requirements.  For instance:

 my @nums[0..*:by(2)];
 @nums[2 * $_] = $_ for 0..5];
 say @nums[ *[-1] ]; # same as 'say @nums[10];'
 @nums[42] = 21;
 say @nums[ *[-1] ]; # same as 'say @nums[42];'
 say @nums[ *[-2] ]; # same as 'say @nums[40];' - whatever that means.

: 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.

That's more or less how I was thinking of it, though I hadn't got as
far as boolean context.

I'm still debating the boolean context myself.  I _think_ it will
work; but I have a tendency to miss intricacies.  You might instead
want to require someone to explicitly check for definedness or
existence instead of merely truth; or you might not.

: If we use this notation, then
:
:  @array[ *; * ]
:
: is shorthand for
:
:  @array[ @array.shape[0]; @array.shape[1] ]

Note also that multidimensional whatever gives us

    @array[ ** ]

to mean

    @array[ @@( @array.shape[*] ) ]

or some such.

Like I said, I tend to miss intricacies.  For instance, I never
considered what would be involved in applying a subscriptor to a
multidimensional Whatever (e.g., what can you do with '**[...]'?).
Part of that is that I'm not yet comfortable with multidimensional
slices (or arrays, for that matter); when reading about them, I keep
on getting the feeling that there's something going on here that the
big boys know about that I don't - implicit assumptions, et al.

Though ** might want to be even smarter than that if
we want

    @array[ 0; **; 42]

to dwim.  That'd have to turn into something like:

    @array[ 0; @@( @array.shape[*[1]..*[-2]] ); 42 ]

Also +** might return a shape vector, or maybe +«**.

If by "shape vector" you mean something that says "the array has a
length of 5, a width of 3, and a height of 2", +«** would seem to be
the more appropriate syntax.  Why you'd want that inside an array's
subscriptor is beyond me, for a similar reason to +*.  But that's what
the logic of the syntax gives.

But I _could_ see using '[EMAIL PROTECTED]' to get an array's measurements.

Hmm...

 my @@square = (1, 2; 3, 4);
 say +@@square; # say what?  '2', as in 2 dimensions?  Or '4', as in 4 items?

Answer that, and you'll know what +** would give you.

--

BTW: could the parser handle the following?

 @array[ *[0] * 2; 2 ** **[ [;] 0 x *] ]

--
Jonathan "Dataweaver" Lang

Reply via email to