MonkeeSage
12/19/2007 2:39:00 PM
On Dec 19, 2:12 am, DNNX <6aLLIaPu...@gmail.com> wrote:
> On 19 ???, 01:42, MonkeeSage <MonkeeS...@gmail.com> wrote:
>
>
>
> > On Dec 18, 10:23 am, DNNX <6aLLIaPu...@gmail.com> wrote:
>
> > > On 18 ÄÅË, 17:54, Robert Klemme <shortcut...@googlemail..com> wrote:
>
> > > > On one hand you are right. On the other hand, begin and end indexes
> > > > are asymmetric anyway: you know that the starting index is always 0
> > > > but the ending index can have arbitrary values. ...
>
> > > Hm... On the other hand, end and begin indexes are asymmetric anyway:
> > > you know that the ending index is always -1 but the starting index can
> > > have arbitrary values.
>
> > > Isn't this a symmetry?
>
> > > Best regards,
> > > Viktar
>
> > No, because "-1" is a special value...it's got magic in it. It can
> > magically mean 5, or 10, or even 12 (because it's magic). ;) "-1" is
> > just sugar for #length, and #length is always a side-effect of a
> > container, whereas '0' is a constant entry point.
>
> > Regards,
> > Jordan
>
> -1 is more special and magic than 0? Hm... 0 also can magically mean
> -6, -11, or even -13 (because it's magic too).
>
> -1 is sugar for #length? Not sure I understand correctly. Never heard
> such an interpretation of -1 earlier. Why #length but not #length-1?
> Why 0 is not
> sugar for -#length? What do you mean saying -1 is a sugar for
> something?
>
> 0 is a constant entry point? Great, -1 is a constant exit point.
>
> Anyway, is there any symmetry or no, I still believe that returning
> 'asd' in one case and nil in other is not consistent (please see my
> example in the first message).
>
> Regards,
> Viktar
I think you (and Michal) missed my point. And yes, I should have said
#length-1. The point is, since there is *no such thing* as a negative
index -- 0 is the *first* index -- and "-1" (or -anynumber) is just
sugar (i.e., just a more convenient syntax for writing #length-
whatever), what you're asking is for ranges such as [-7..2] and [1..0]
to be meaningful. Taking your example, "'asd'[-10..-1]", this means
'asd'[-7..2] when you de-sugar it. Now in the other case,
"'asd'[0...10]", once you reach #length-1, you can stop and return
0..#length-1. But with 'asd'[-7..2], what are you supposed to do when
the start index is less than the first index (0)? Well, you could skip
ahead to the first index, sure, but it makes just as much sense (if
not more) to return nil/empty string. Same goes for cases such as
'asd'[-2..-3] (i.e., 'asd'[1..0]), where the start index is greater
than the end index.
Regards,
Jordan