From: Greg Fodor Date: 2007-05-25T08:20:09+09:00 Subject: Re: Introducing the "it" keyword > Maybe you could do: > > return v + 1 if its < 10 > > -- snip > > return v + 1 if < 10 Unfortunately this seems much more difficult and ambiguous for a number of reasons. First, it is impossible to know that our implied "it" should be "v + 1" without making assumptions about the intent. (Why don't we include the result of the return expression itself? What if it's more complex?) More importantly, semantics of order of evaluation become confusing. Despite v + 1 being evaluated during the if conditional, it syntactically appears in the return statement. My approach preserves all current ruby semantics and is more intentional, I feel. It basically transforms this: tmp = m(x) h(tmp) if g(tmp) into just h(it) if g(it = m(x)) The it keyword is essential for one reason and nice for a few others. It is essential because of the ruby semantics for determining identifiers vs. methods, referenced in my original post. It is nice because we no longer have to come up with the name "tmp,"ruby provides a consistent intentional name. It is also nice because it is less code. It is also nice because it provides correct scope semantics so it will be GCed at the optimal time. > No need for it to be such a special built-in construct. Depends on what you mean by "need." For an optimal solution, I feel it does. "Optimal" means: - It only evaluates m(x) once (yours does this) - It is the most terse representation of intent (subjective) - It introduces the correct scope (yours does not) - It releases memory upon GC after the statement (yours doesn't) - It avoids side effects (yours changes global space) Its hard to think of a solution to this implemented in ruby that fits these parameters without introducing a new language level construct.