2008/5/26 Radosław Bułat < radek.bulat gmail.com">radek.bulat gmail.com>:
Hey!
I've tried your patch and have some troubles.
I expected to this code:
def test
yield
yield(2)
end
test {|x=10| p x}
to print
10
2
but it prints
10
10
I39;ve tried also with &block but the same results. At the end of this message is an update for this patch that fixes the above. I had to change vminshelper.c. Apparently there is two completely separate functions for handling arguments (lambda vs. block/proc). I updated the block/proc one for handling optional args. Seems like some refactoring should be done.
Also I updated the tests to call all of these with various blocks (instead of using lambda directly):
[method(:lambda), method(:proc), Proc.method(:new), lambda{|&b|b}].each do |lam| ... end
But worse problem was with irb. When I run irb1.9 (with this patch)
memory usage has jumped to > 50% (I have 2GB) and irb prompt didn't
even show. Don't you have this issue? I haven' t seen this, but I working off of r16568 (problem looks to start at r16615).
Here's the updated patch:
Index: sample/test.rb ===================================================================
--- sample/test.rb (revision 16568) +++ sample/test.rb (working copy)
 -296,6 +296,61   test_ok(f.call([42,55]) == [[42,55]]) test_ok(f.call(42,55) == [42,55]) +[method(:lambda), method(:proc), Proc.method(:new), lambda{|&b|b}].each do |lam|
+ + f = lam.call { |a, b=42, *c| [a,b,c] } + test_ok(f.call(1 ) == [1,42,[ ]] ) + test_ok(f.call(1,43 ) == [1,43,[ ]] ) + test_ok(f.call(1,43,44) == [1,43,[44]] ) + + f = lam.call { |a, b=(a|16), *c, &block| [a,b,c,block&&block[]] }
+ test_ok(f.call(8 ) == [8,24,[ ],nil] ) + test_ok(f.call(8,43 ) == [8,43,[ ],nil] ) + test_ok(f.call(8,43,44) == [8,43,[44],nil] ) + test_ok(f.call(8 ) == [8,24,[ ],45 ] )
+ test_ok(f.call(8,43 ) == [8,43,[ ],45 ] ) + test_ok(f.call(8,43,44) == [8,43,[44],45 ] ) + + f = lam.call { |a, b=42, *c, d| [a,b,c,d] } + test_ok(f.call(1 ,99) == [1,42,[ ],99] )
+ test_ok(f.call(1,43 ,99) == [1,43,[ ],99] ) + test_ok(f.call(1,43,44,99) == [1,43,[44],99] ) + + f = lam.call { |a, b=(a|16), &block| [a,b,block&&block[]] } + test_ok(f.call(8 ) == [8,24,nil] )
+ test_ok(f.call(8,43) == [8,43,nil] ) + test_ok(f.call(8 ) == [8,24,45 ] ) + test_ok(f.call(8,43){45} == [8,43,45 ] ) + + f = lam.call { |a, b=42, d| [a,b,d] } + test_ok(f.call(1 ,99) == [1,42,99] )
+ test_ok(f.call(1,43,99) == [1,43,99] ) + + f = lam.call { |b=42, *c, &block| [b,c,block&&block[]] } + test_ok(f.call( ) == [42,[ ],nil] ) + test_ok(f.call(43 ) == [43,[ ],nil] )
+ test_ok(f.call(43,44) == [43,[44],nil] ) + test_ok(f.call( ) == [42,[ ],45 ] ) + test_ok(f.call(43 ) == [43,[ ],45 ] ) + test_ok(f.call(43,44) == [43,[44],45 ] ) +
+ f = lam.call { |b=42, *c, d| [b,c,d] } + test_ok(f.call( 99) == [42,[ ],99] ) + test_ok(f.call(43 ,99) == [43,[ ],99] ) + test_ok(f.call(43,44,99) == [43,[44],99] ) + + f = lam.call { |b=42, &block| [b,block&&block[]] }
+ test_ok(f.call( ) == [42,nil] ) + test_ok(f.call(43) == [43,nil] ) + test_ok(f.call( ) == [42,45 ] ) + test_ok(f. |