Why the 'next' call within the Proc obj created by 'lambda'

Hi, guys,

I am one of the chinese translators for “Programming Ruby 2nd”. And
one reader in China reported that the ‘next’ call within the Proc obj
created by ‘lambda’ always returns nil, instead of the specified
value.

E.g., (the code snippets is from page 358)

pr = lambda {next 99}
puts pr.call

While, for the Proc obj created by Proc#new, it works fine.

Could you please have a look, why 1.8.5/6 changed to that way? Or it’s
just a bug?

Regards,

I would like to see any comments to this question too.

irb(main):001:0> pr = Proc.new {next 99}
=> #Proc:[email protected]:1(irb)
irb(main):002:0> pr.call
=> 99

irb(main):003:0>
irb(main):004:0* pr = lambda {next 99}
=> #Proc:[email protected]:4(irb)
irb(main):005:0> pr.call
=> nil

Does seem counter to what is written in the PickAxe, “next” in case of
Proc
created by Kernel.lambda does not return the value passed to it,
though
it does exit the block.

  • Nasir

Hi,

In message “Re: Why the ‘next’ call within the Proc obj created by
‘lambda’ always returns nil on ruby 1.8.6?”
on Mon, 16 Apr 2007 23:39:00 +0900, FindSun [email protected]
writes:

|pr = lambda {next 99}
|puts pr.call # => nil

It is a bug. I fixed it. Thank you.

          matz.