From: Jason Creighton Date: 2003-07-21T08:17:48+09:00 Subject: Re: chaining comparisons On Sun, 20 Jul 2003 14:22:37 +0900 Joel VanderWerf wrote: > Jason Creighton wrote: > > On Sat, 19 Jul 2003 14:58:51 +0900 > > "Kurt M. Dresner" wrote: > > > > > >>When I learned python I was overjoyed that I could evaluate 1 < 2 < 3 > >>and get "true". I just realized that you can't do that in Ruby. Is > >>there a reason why? Is it good? I know I can use "between", but > >>still... > > > > > > http://www.rubygarden.org/article.php?sid=286 > > > > So basically, it's because it's hard to implement, even more so because > > true/false/nil are singleton objects. (So you can't, for instance, save state > > in a particular instance of 'true', because there's only one.) > > As you say, there is only one true; but you still can save state in it: > > irb(main):001:0> true.instance_eval {@x = 1} > 1 > irb(main):002:0> true.instance_eval {@x} > 1 > > Not that it's relevant to the 1 < 2 < 3 discussion, but it's kinda cute... Yeah, it is kinda cute. How does that work? It works for Fixnum objects, too..... >> (0..16).each { |n| n.instance_eval { @square = n*n } } => 0..16 >> 5.instance_eval { @square } => 25 How can that work when Fixnum is stored in VALUE? And that's another thing: VALUE is either an immediate value (Fixnum/true/false/nil) or a pointer to an object. Doesn't that mean there's only 31 bits (on 32 bit machins) available for the pionter? How can that work? I always thought that pointers would have to be able to cover the whole address space.... Jason Creighton