On Jan 8, 2007, at 11:19 PM, Evan Phoenix wrote:
[snip]
> The other expected behavior is that block arguments are seen to all  
> code 'below' the block and not to any code above.. For example:
>
> a = [1,2]
> a.each do |i|
>   m = "hello"
>   i.upto(10) do |j|
>     n = "evan"
>     # i, j, n, m are seen here.
>   end
>
>   # j is NOT seen here.
>   # i, m and n are seen here.
> end
>
> # i and j are not NOT seen here.
> # m and n are seen here.

I'm not sure how the above code corresponds with your statement  
above. Why are m and n seen at the end, but not i and j? Is the end  
of the code not 'below' the block? Why are block-local variables (m  
and n) going to be seen outside of their block?

I certainly would find it very unintuitive (not expected) if this  
code worked:

   def foo
     bar = 12
   end
   foo
   p bar
   #=> 12

which seems to be part of what you are suggesting above. The only way  
m and n should be 'seen' in your above example is if they are  
assigned values before the block is invoked, thus allowing them to be  
referenced by the closure.


Finally...with respect to block variables i and j, I don't see  
anything that you are proposing above that is in conflict with either  
what Matz is suggesting for 2.0 or what exists currently in 1.8. (But  
perhaps I'm missing something; it is past my bedtime and my mind may  
be tired.)