Austin Ziegler wrote:
> On 10/18/05, Sean O'Halpin <sean.ohalpin / gmail.com> wrote:
> > On 10/18/05, Eric Mahurin <eric_mahurin / yahoo.com> wrote:
> > > But, I kind of still
> > > wish we had a syntax where the variables in a block/lambda were
> > > local (non-closure) by default.
> > Maybe if we say it often enough? ;)
>
> Doubtful. I think to convince matz, real examples would need to be
> presented (as an RCR!) as to why this is necessary. IANM, but IMO
> theoretical need and wish ain't sufficient.

The easist is the old gotcha. Programmer has code (doesn't much matter
what it is)

  class X
    def foo
      l = lambda { |a| x = a**2; x + 1 }
      return l[1],l[2]
    end
  end

  class Y
    def bar( n )
      x = n * 3
      return x
    end

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.

For something a little more concrete:

  class X
    def x ; 1;end
   end
   => nil

   class Y < X
     class X
       def x;2;end
     end
     def x;3;end
   end
   => nil

   X.new.x
   => 1
   Y.new.x
   => 3
   Y::X.new.x
   => 2

Now try:

  class X
    def x;1;end
  end
  => nil

  Y = Class.new(X) do
    X = Class.new do
      def x;2;end
    end
    def x;3;end
  end
(irb):5: warning: already initialized constant X
  => Y

  X.new.x
  => 2
  Y.new.x
  => 3
  Y::X.new.x
  (irb):12: warning: toplevel constant X referenced by Y::X
  => 2

T.