Juerd wrote: > John Williams wrote: > > > 4 :th > > > $foo :th > > No. Adverbs modify verbs (operators or functions), not terms like 4 or > > $foo. > > Then perhaps a method? Number::th? > > 4.th > $foo.th
Again, with a bit of magic where the dot is optional when the object in question is an integer literal: 4th =:= 4.th - and probably with special synonyms for th when the literal is any of (1 or -1, 2 or -2, 3 or -3) - Number::st, Number::nd, and Number::rd, respectively. Mind you, these wouldn't _really_ be methods, since they would only be valid when used within the arguments of a list's postcircumfix:[] operator. And while I like the notion that 0th has a valid meaning and that its meaning fits into a scheme that parallels the wraparound behavior of standard lists (i.e., perl 5's 0-based contiguous lists), I can see the arguments for both 1st referring to the first element and -1st referring to the last argument (which, if both are accepted, would leave 0th out in the cold). Of the two, "1st =:= first" is the more compelling argument; and if one of the two arguments has to be rejected, I'd rather it be the "-1st =:= last" one. So we've come up with two mutually exclusive schemes for ordinal indices, depending on which of 0th or -1st refers to the last element of a list. There's a third option where the last element isn't given an ordinal at all; but I doubt that anyone would prefer this, even as a second choice. The pros and cons of each approach have now been discussed at length, and it appears that we've reached an impasse of sorts. So let me just summarize the positions, and ask for Larry's thoughts on the issue. "0th =:= last": Lists using this type of ordinals would behave exactly like a perl 5 list, except that [$n.th] would correspond to [$n-1] rather than to [$n]. You'd read non-positive ordinals as offsets from the last element, which isn't quite symmetric with the way that positive ordinals would be read. "-1st =:= last": This type of ordinal index maintains a symmetry between positive and negative indices, treating the sign of the ordinal as an indication of which end of the list to start at. C<0th> would be undefined, which makes some intuitive sense; but you'd have to watch out for such things as (1 + $n).th, which would throw an error if $n was -1, and would work differently for $n < -1 and $n > -1. Either way, I'd be in favor of being able to use C<last> as a synonym for the ordinal corresponding to the last element in a list (and, for symmetry, C<first> as a synonym for 1.th or 1.st); it's at worst one character longer than the ordinal in question, and its meaning is clear and unambiguous. The only problem with it is when you're dealing with sparse arrays: [last - 1] won't neccessarily do what you want it to, depending on what you want it to do. To avoid confusion in the discussion, let's look at the other end (where we're pretty much agreed on the meaning of 1st and first): if we want to look at the next existing element, we can say (1 + 1).th; if we want to look at the element whose index is one higher than the first index, we can say 1.st + 1. With C<first>, we can do the latter but not the former. ===== Jonathan "Dataweaver" Lang _______________________________ Do you Yahoo!? Win 1 of 4,000 free domain names from Yahoo! Enter now. http://promotions.yahoo.com/goldrush