From: Brian Candler Date: 2004-10-05T20:20:44+09:00 Subject: Re: [RCR] New [] Semantics On Tue, Oct 05, 2004 at 08:11:52PM +0900, Florian Frank wrote: > >Yes, see adjacent thread. What it actually does is iterate all value > >from > >start to end using succ, and set a flag to true when it finds a match > >(but > >it doesn't break out of the loop when a match is found) > > This seems the wrong thing to do. The documentation says: > > ---------------------------------------------------------- Range#member? > rng.member?(val) => true or false > ------------------------------------------------------------------------ > Return +true+ if _val_ is one of the values in _rng_ (that is if > +Range#each+ would return _val_ at some point). > > I would think that it should return true, instead of going round in > circles. I agree, although it's really only an optimisation, because other cases will still give an infinite loop: in particular i = 1.0/0 (2..i).member?(1) So you have a halting problem instead :-) > The Enumerable version works ok: > > >> Enumerable.instance_method(:member?).bind(0..(1.0/0)).call(4) > => true Yes, it breaks out of the loop. > I would prefer getting rid of the overriden member? implementation > in range.c. Or fixing it, but I'd also be happy to see it fall back to Enumerable, as there's not much efficiency gain in implementing basically the same thing a second time within range.c Regards, Brian.