From: "Jean-François Trân" Date: 2008-10-22T01:12:38+09:00 Subject: Re: Ruby way to take some action only once in a loop? 2008/10/21 Evgeniy Dolzhenko : > The most embarrassing fact about Nobu's solution is its all in Pickaxe > http://www.rubycentral.com/pickaxe/tut_expressions.html :) > > Exactly what happens is described in this quote: "You can use a Ruby range > as a boolean expression. A range such as exp1..exp2 will evaluate > as false until exp1 becomes true. The range will then evaluate > as true until exp2 becomes true. Once this happens, the range resets, > ready to fire again". > > So exp1 (first=true) evaluates to true, then interpreter evaluates > boolean range > to true and waits until exp2 (false) becomes true which will never happen, > but on all consequent runs "and first" will guard "if" body from executing thanks for the explanations. > (because exp1 is not executed anymore "first" gives you nil, > AFAIK what happens here is that "first" becomes "defined" name for the > interpreter > after first assignment but I can't say I have good grasp on this > "scoping" feature). I guess it can be explained because at parse time, Ruby has seen first assignment in the condition, and then considered 'first' as a variable even if the assignment is not executed. it's also in the Pickaxe :) http://www.rubycentral.com/pickaxe/language.html chapter : Variable/Method Ambiguity -- Jean-François. -- Les 50 ans du Lisp : http://www.lisp50.org http://twitter.com/underflow_