From: Gunnar Date: 2005-05-04T02:29:45+09:00 Subject: Re: Pickaxe page 342, Ranges in Boolean Expressions --I don't understand Jacob Fugal wrote: > On 5/3/05, Gunnar wrote: >> Hi all >> I can not make sense of the boolean ranges. The example >> (11..20).collect {|i| (i%4==0.. i%3==0)?i:nil} => [nil, 12, nil, nil, >> nil, 16, 17, 18, nil, 20]. >> >> I can figure out all numbers except the '18', which in my opinion should >> be a 'nil' since i%3==0 is true and would cause the state to change from >> SET to UNSET. Is the state machine Fig 22.1 correct? > > It appears to me that the second condition in the range UNSETs, but > inclusively (which makes sense for the semantics of '..'). That's why, > for example, 12 is printed at all... 12%4==0, so it SETs, retval is > set to true since it is SET, then 12%3==0 so it UNSETs. But the retval > is already set, and it returns true, thus printing 12. > > In the same way, when we get to 18, the state machine is already SET > (since 16). retval is set to true since it is SET, then 18%3==0 so it > unsets. But just like with 12, retval is already set, so it returns > true and prints 18. > > For more information see [ruby-talk:91137]. > > Jacob Fugal > > [ruby-talk:91137] > [http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/91137 OK. Thank you for answering so very quickly Gunnar