On Fri, 13 Oct 2000, Dave Thomas wrote: > Davide Marchignoli <marchign / di.unipi.it> writes: > > > Which is the rationale of the fact that block variables are non-binding > > if some variable with the same name already exists ? Isn't it confusing? > > It can be confusing, but it's also a benefit. It allows blocks to be > used as closures, retaining access to local scope even if that scope > has gone out of context. > > def example > a = 99 > return proc { |n| n + a } > end > > x = example > x.call(2) # => 101 > Probably my question was not clear, I was not talking about a. For sure, if one wants to mantain lexical scoping (and so we also get closures) a has to be bound to the variable created within procedure example. My question was about variable n, the block does not necessarly introduces a fresh variable, instead it (possibly) binds it to an already existing variable. IMHO this treatement of variables occurring as argument of blocks is unrelated to the creation of closures. Thanks, Davide