On Sat, 4 Sep 2004, David Green wrote:

> In article <[EMAIL PROTECTED]>,
>  [EMAIL PROTECTED] (Larry Wall) wrote:
> >I'm still thinking A is the first one and Z is the last one.  Someone
> >talk me out of it quick.
>
> The actual issue is how to distinguish cardinal numbers from ordinals,
> right?  So if we want ordinal numbers, why not use ordinals?
>
>      say "From the home office in Moose Jaw, Saskatchewan:";
>      say @top_AZ_alternatives[1st .. 10th];
>
> So the first element is 1st (or 1th), and the last is -1st.  Or maybe 0th
> is the first? No, that's silly, 1st should be first.  0th could be the
> element before the first, and I suppose -0th means after the last.  (If
> you read from the 0th/-0th element of an array you presumably get undef,
> and you could write to it to unshift/push.)

Very close.  I really like counting from the front using a postfix operator
"th" (you'd also want "st" and "nd" to be synonymous, and maybe a special
"first") but it seems to me trying to count backwards in that scheme just
doesn't quite work.  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".  Of course, getting any of this to actually work seems
tricky, but doesn't seem any harder than A or Z, and would read extremely well.

> We already have ordinals for grammars, so I'm sure we could make 'em work
> here.  (Maybe "nth()" is an operator that constructs ordinal-objects?
> (I kind of want a "th" suffix operator so I can do ($n)th.  Although that
> doesn't really lend itself to counting from the end, like the supposed
> "-nth" operator, unless you can do something like "($n)th but backwards"
> ... eh, which may not be worth it.))

I don't see any reason why "st", "nd", and "th" couldn't be postfix operators
instead of prefix.
-- 
Adam Lopresto
http://cec.wustl.edu/~adam/

"The prince wants your daughter for his wife."
"Well, tell him his wife can't have her."
- Blackadder III

Reply via email to