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

**URL:** <https://www.ruby-forum.com/t/why-the-next-call-within-the-proc-obj-created-by-lambda/92143>\
**Category:** Ruby\
**Created:** [April 16, 2007, 4:39pm UTC](https://www.ruby-forum.com/t/why-the-next-call-within-the-proc-obj-created-by-lambda/92143 "2007-04-16T16:39:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FindSun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb8c5e/32.png) [@FindSun](https://www.ruby-forum.com/u/FindSun)\
**Post date:** [April 16, 2007, 4:39pm UTC](https://www.ruby-forum.com/t/why-the-next-call-within-the-proc-obj-created-by-lambda/92143/1 "2007-04-16T16:39:55Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![FindSun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb8c5e/32.png) [@FindSun](https://www.ruby-forum.com/u/FindSun)\
**Post date:** [April 17, 2007, 7:18am UTC](https://www.ruby-forum.com/t/why-the-next-call-within-the-proc-obj-created-by-lambda/92143/2 "2007-04-17T07:18:28Z")

</div>

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

irb(main):001:0\> pr = Proc.new {next 99}  
=\> #Proc:0x02c5cbe4@:1(irb)  
irb(main):002:0\> pr.call  
=\> 99

irb(main):003:0\>  
irb(main):004:0\* pr = lambda {next 99}  
=\> #Proc:0x02c58684@: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

---

<div class="post-metadata">

**Author:** ![FindSun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/eb8c5e/32.png) [@FindSun](https://www.ruby-forum.com/u/FindSun)\
**Post date:** [April 17, 2007, 9:52am UTC](https://www.ruby-forum.com/t/why-the-next-call-within-the-proc-obj-created-by-lambda/92143/3 "2007-04-17T09:52:38Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

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

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

```
          matz.

```
