Hello -- On Mon, 8 Jan 2001, Christoph Rippel wrote: > > -----Original Message----- > > From: David Alan Black [mailto:dblack / candle.superlink.net] > > Sent: Sunday, January 07, 2001 02:00 PM > > To: ruby-talk ML > > Subject: [ruby-talk:8788] Re: Backward Range implementation > > > > > > Hello -- > > > > On Sun, 7 Jan 2001, Kevin Smith wrote: > > > > > > > > Here's what I came up with that seems to work. I > > > didn't exhaustively test all the methods of > > > Range, but I think I probably hit the ones that > > > weren't working. Oh, I don't expect backward > > > ranges to support exclusive mode (it seems > > > unbalanced), so I didn't test that. > > > > > > Gotta love this language > > > > > > Kevin > ... > > Further thoughts/hacks/enhancements/whatever? > > > > > > David > There is probably some code out there which relies on > the semantics that ``(0..-1).each do |i| whatever(i) end'' > does nothing. No doubt. The code Kevin and I were writing is not backward-compatible, at least not language-wide. > It seem more prudent to introduce a separate ``each_down'' > iterator defined whenever a method ``#pred'' is provided? Or based on the idea that any range can be reversed. Which would mean that "(x .. y).to_a == (y .. x).to_a.reverse" would always be true, even if (as with strings) there was no subtraction (or #pred) method. Something like: class Range def in_reverse(&block) to_a.reverse.each &block return self end end ('a' .. 'd').in_reverse do |e| puts e end => d c b a though it would be nice (I think) not to even have to know before runtime whether you might have a backward-running range. David -- David Alan Black home: dblack / candle.superlink.net work: blackdav / shu.edu Web: http://pirate.shu.edu/~blackdav