From: Ronald Fischer Date: 2007-05-29T16:55:01+09:00 Subject: Re: Introducing the "it" keyword > > A more > > general solution could be like this: > > > > let a+b+c in > > let foo=d*e in > > let x/y in > > puts ($1+foo)*($1-$2)-$2/($1-foo) > > > > Here, $1 would be bound to x/y (innermost unnamed let > > binding), $2 would > > be bound to a+b+c (second innermost unnamed let binding). > > You're working too hard: > > def let(*args) > yield *args > end > > def use_let(a,b,c) > let a+b+c do |it| > return it if it < 10 > end > end > > use_let(1,2,3) # 6 > use_let(4,5,6) # nil > > No need for additional keywords or even global variables, > just a little > method named let. With the crucial difference that in your solution, you are *required* to name the bound variable (here: it), while in my proposal, you are not. I think if we only want to introduce an auxiliary variable as "abbreviation" for an expression which occurs repeatedly in a block, Ruby indeed has many ways to do it, as do most other languages I know. The problem becomes interesting IMO if we are libarated from the requirement to invent a name for such a variable. The OP suggested to have a "reserved variable" named 'it' which is kind of implicitly bound, but this is a special case for a special type of programming pattern. My alternative suggestion go into a more general direction, where you can have more than one binding, and where it is the programmer's choice whether or not to name the variables. Ronald -- Ronald Fischer Phone: +49-89-452133-162