On 10/19/05, Trans <transfire / gmail.com> wrote:
> Austin Ziegler wrote:
>> On 10/18/05, Trans <transfire / gmail.com> wrote:
>>> The easist is the old gotcha. Programmer has code (doesn't much
>>> matter what it is)
>> [...]
>>> And wants to resue the lambda so uses old fashion copy and paste:
>>>
>>>   class Y
>>>     def bar( n )
>>>       x = n * 3
>>>       l = lambda { |a| x = a**2; x + 1 }
>>>       return x + l[3]
>>>     end
>>>   end
>>>
>>> Oopsy.
>> Dumb programmer. This part isn't nearly sufficient to justify a new
>> scope or kind of lambda (lambda without closure), IMO. If you want to
>> reuse a lambda that you're not passing around, make it a method.
> Dumb example. But I wasn't foging for "gold". Surely you can
> extrapolate beyond this. Take a class context for instance, used to
> define a few methods on a template. Class methods could interfere,
> etc.

I'm not wanting to extrapolate. Consider me the conservative here,
Trans. Convince me that this is really useful and important.

> [...]

>> This isn't a closure problem. This is a constant lookup problem, and
>> Matz has said that this should be fixed moving forward.
> It has to do with closures in that the reference to constants is
> relative to the given closure. So the current behavior is correct. A
> non-closure block will allow the needed alternate behavior.

Not by my understanding. Constant lookup is handled separately from
closure rules, which mostly deals with local variables. That is to say
that:

  class X; end
  Y = Class.new(X) do
    X = Class.new do
	end
  end

is and should be different than:

  class X; end

  x = X
  p x # X

  Y = Class.new(X) do
    x = Class.new do
	end
 	const_set("X", x)
  end

  p x # Y::X

Closure rules don't ahve anything to do with constant lookup, at least
at this point.

-austin
--
Austin Ziegler * halostatue / gmail.com
               * Alternate: austin / halostatue.ca