Nobuyoshi Nakada wrote:
> How about making all local variables other than block arguments
> method/class/toplevel?

On the plus side:

  def my_find(a)
    # res=nil not needed!
    a.each { |e| res = e if e =~ /foo/ }
    res
  end

On the minus side:

  m = lambda { |x,y| tmp = x*2; tmp + y }

Here tmp becomes a "static" variable (in C-speak) by default, unless you 
write

  m = lambda { |x,y;tmp| ... }

I think this could cause hard-to-find bugs if the lambda is invoked from 
multiple threads, and a lot of confusion for people expecting functions 
written in this form to be side-effect free.

I guess it could become another difference between lambda and 
Proc/block. I'm not sure if that would make things less confusing or 
more.

I still think the current rule ("tmp is part of the closure if it is 
assigned to earlier in the method") is much more sane than the suggested 
alternative ("tmp is part of the closure if it is assigned to earlier 
*or later* in the method")
-- 
Posted via http://www.ruby-forum.com/.