On Sunday, May 9, 2004, 7:23:12 AM, Jeff wrote:

(where x == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

>> Yes the anomaly is that ruby only modularizes indices i for
>> -length <= i < length.  A purist might say modular arithmetic
>> should be applied globally or not at all, but this would give 
>> 
>> x[10..15] == x[20..25] == x[-20..-15] == [1,2,3,4,5,6]

I'd happily accept x[10..15] == x[20..25] == x[-20..-15] == []

>> which could fail to indicate Something's Wrong.  I see ruby's
>> subset of modular arithmetic as a middle ground between convenience
>> and saftey.  One can always write ModArray trivially, after all.

> Whoa hang on, I didn't read the OP well enough.  At least x[-3..2]
> should return [8, 9, 10, 1, 2, 3], otherwise this isn't even a
> subset of modular arithmetic, it's something else.

Yes, it's Weird.

Take this, though.  Let y = [7, 8].  Now what could y[-1..1] mean?

(-1..1) =~ [-1, 0, 1].  All elements of that range represent fair-game
indices into y.  So:

  y[-1..1] == [8, 7, 8]  ???

That seems wrong!  Yet what is the "intuitive" answer?  [8,7] or
[7,8]?  And why?

So if ranges of this type are going to produce something useful (as
x[-3..2] seems like it ought to), then there would be some pretty
funky rules buried into Array#[].

Cheers,
Gavin