Forum: Ruby Why the 'next' call within the Proc obj created by 'lambda'

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Fd119368b8bbd06f90900516978cb8db?d=identicon&s=25 FindSun (Guest)
on 2007-04-16 16:39
(Received via mailing list)
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

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

pr = lambda {next 99}

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?

9aafe2636a115bbdc137c93445054f22?d=identicon&s=25 Nasir Khan (Guest)
on 2007-04-17 07:18
(Received via mailing list)
I would like to see any comments to this question too.

irb(main):001:0> pr = {next 99}
=> #<Proc:0x02c5cbe4@(irb):1>
=> 99

irb(main):004:0* pr = lambda {next 99}
=> #<Proc:0x02c58684@(irb):4>
=> nil

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

- Nasir
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2007-04-17 09:52
(Received via mailing list)

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 <>

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

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

This topic is locked and can not be replied to.