Jonathan Lang skribis 2004-09-07 14:12 (-0700):
> 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.  

Why would they be invalid outside? Ordinals as real possible values make
sense to me.

Say, you have an array @foo, that starts counting at 5, and @bar that
starts counting at 10. Both have 5 elements. Wouldn't this be handy?

    for 1 .. 5 {
        ... @foo[.th] ... @bar[.th] ...
    }
    
    # or maybe even:

    for 1st .. 5th {
        ... @foo[$_] ... @bar[$_] ...
    }

    $nth = 1st;

    say @foo.resolve $nth;  # 5  # could be useful

    # In normal situations, one would of course use:
    #     for @foo Y @bar -> $foo, $bar { ... }
    # but that is besides the point.

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

I used to think I wanted 0th to be the 0th (one before the first),
because 1nd + $foo could logically only mean (1 + $foo)th. However, if
th is a method of Number, you can just use literally (0 + $foo).th, and
there is no need for a 0th in this anymore.

Still, though -1st seems more logically to me, especially since +1st
isn't 0-based either.

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

I read this three times, but don't get it. Can you please explain what
the difference is between the element after the 1st and the element
whoso index is one higher than the 1st's?


Juerd

Reply via email to