From: David Alan Black Date: 2002-04-30T07:07:42+09:00 Subject: Re: [RFC] Ranges - enable (10..-10) Hello -- On Tue, 30 Apr 2002, Michal Rokos wrote: > Hello, > I've looked that negative ranges are not allowed in Ruby. > > I'd like to discuss, if it is possible permit them... > > Example: > (10..-10).each |i| do puts i end > does nothing in current Ruby > (10..-10).step(2) > does nothing in current Ruby > > This patch make the example works (and fixes some funny step's value > like 0 (causes never ending loop) and < 0 (causes overroll). > > I'm waiting for your comments :-) > > Michal In [ruby-talk:8993], matz said: The truth are: * A range enumeration cannot go back, it's upward only. * But A range with end point less than start point is valid. * Thus 1..-1 is a completely valid range object. * Array and String internally convert negative end point into size+n, where n is a negative number. * So range n..-m is interpreted as n..(size-m), thus works fine (if n <= (size-m)). I can't claim I've totally grasped why a range is upward by definition... but apparently it is, so that's *my* problem :-) You'll find a few other posts if you search for "backwards range" or "reverse range" at ruby-talk.org. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav