Larry Wall wrote:
And @x[*] would be

    @x[*+0..^*-0]

written out that way.  Or possibly

    @x[-* ..^ +*]

depending on how we define the unaries.

Hmm... how about this:

Normally, * in the context of an indexer acts as a Range object,
covering the range of available indices (defined inclusively).  I'm
assuming that Range objects provide methods for accessing the lower
and upper bounds of the range (probably 'min' and 'max'); these
methods could be used to refer to the start and end of the array
explicitly.

When coerced to Num, * points to the first element of the array and
enables negative-index dwimmery relative to it - i.e., '* + Int'
(where Int < 0) counts from the end (with '*-1' being the end), while
'* + Int' (where Int >= 0) counts from the start (with '*+0' being the
start).  Or perhaps it uses Oroborus dwimmery, with too-large indices
wrapping back around to where they started: @x[*+5] is the same as
@x[*+0] for a five-element array.

So:

 @x[*] # every element

 @x[*.min] # first element
 @x[*.min+0] # first element
 @x[*.min+1] # second element
 @x[*.min-1] # just before first element

 @x[*.max] #last element
 @x[*.max+0] # last element
 @x[*.max+1] # just after last element
 @x[*.max-1] # second to last element

 @x[+*] # first element
 @x[*+0] # first element
 @x[*+1] # second element
 @x[*-1] # last element

Unshaped arrays work exactly like shaped arrays; so perl 5's '$x[-1]'
becomes '@x[*-1]', while '@x[-1]' is a reference to just before the
first element (and assigning a value to it shapes the array to include
it within the lower bound).

That said, I'd like to be able to spell '[*.min]' as '[1st]',
'[*.min+1]' as '[2nd]', and '[*.max]' as '[last]'; but I could live
without 'em.

--
Jonathan "Dataweaver" Lang

Reply via email to