From: Logan Capaldo Date: 2007-09-10T00:47:18+09:00 Subject: Re: Bug in lambda? On 9/9/07, Bernardo Monteiro Rufino wrote: > On 9/9/07, dblack@wobblini.net wrote: > > > As far as remember, Guy Decoux and I are the only two people who think > > that this makes perfect sense, once you learn it, and should not be > > changed :-) > > > > I think it shouldn't be changed too... > I just think it has icky semantics. a.rb: fib = lambda do |a| if a == 1 or a == 0 1 else fib[a - 1] + fib[a - 2] end end p fib.call(10) C:\Documents and Settings\Logan>ruby a.rb 89 vs. b.rb: a = nil fib = lambda do |a| if a == 1 or a == 0 1 else fib[a - 1] + fib[a - 2] end end p fib.call(10) C:\Documents and Settings\Logan>ruby b.rb b.rb:6: stack level too deep (SystemStackError) from b.rb:6 from b.rb:6 from b.rb:6 from b.rb:6 from b.rb:6 from b.rb:6 from b.rb:6 from b.rb:6 ... 633 levels... from b.rb:6 from b.rb:6 from b.rb:6 from b.rb:10 Am I the only one who makes use of recursive lambdas? ;) If we keep assignment semantics for block arguments, I think we should disallow recursive blocks. I don't want recursive blocks to go away personally. I think it's reasonable to give block arguments argument semantics (especially in light of the addition of &block arguments to blocks) instead of assignment semantics. You don't lose any power, although you do lose some "expressivity", eg: a = nil set_a = lambda { |b| a = b } instead of a = nil set_a = lambda { |a| } > -- > Bernardo Rufino >