On 2004/9/04, [EMAIL PROTECTED] (Jonathan Lang) wrote:
(Nice Subject change, I almost missed it!) 

>Larry Wall wrote:
> > Yow.  Presumably "nth" without an argument would mean the last.
>
>If it means the last, why not just use C<last>?

Conflict with "last LOOP"?  Hm, the context should be enough to 
distinguish them, no?  (Hey, maybe they can be unified somehow -- 
"last -1" to skip to the penultimate pass through the loop?  =P)

Anyway, if we can have "last", we should also have "first" (just for 
people who don't mind all the extra typing).

>There is the question about what C<last+1> would mean; intuitively, moving
>forward from the end takes you into limbo; but I can see an advantage in
>wrapping things around such that last+1 == 1st, and 1st-1 == last.

And Adam D. Lopresto wrote:
>That last element isn't "-1st", that's (or at least "(-1)st", 
>depending on precedence) the one before the 0th, which is the one 
>before the 1st.  If you want to count from the end, why not go all 
>the way and use "last", "last-1", "last-2", etc.  "last+1" would be 
>the first element past the current bounds, so "push @foo, $bar" 
>would be the same as "@foo[last+1]=$bar".

Yes, I think counting from the "zeroth last" element is the way to go.  
 So the question then is, should we wrap around or not?  Maybe "first" and 
"last" can keep going off either end of the array, and "nth" can wrap?  Hm.

>Where else could ordinals come in handy?  They're already being used in
>REs, but I'd recommend expanding the usage there to include C<last> and
>possibly C<$n'th> as well as C<1st>, C<2nd>, C<3rd>, etc.  Where else?
>Would there be any use for C[<STDIN>.3rd], frex?

I guess there isn't so much need for a relative index into a file... 
unless maybe you've got some bad sectors and the data doesn't start 
until the fifth line.  =)  Of course, there's a resonance with the 
whole iterator thing...


     -David "but that's still making my head go 'round and around [ha]" Green

Reply via email to