# 1.9 -\> lambda syntax with &

**URL:** <https://www.ruby-forum.com/t/1-9-lambda-syntax-with/153519>\
**Category:** Ruby\
**Created:** [November 18, 2008, 10:29am UTC](https://www.ruby-forum.com/t/1-9-lambda-syntax-with/153519 "2008-11-18T10:29:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [November 18, 2008, 10:29am UTC](https://www.ruby-forum.com/t/1-9-lambda-syntax-with/153519/1 "2008-11-18T10:29:16Z")

</div>

Given  
sum = Proc.new{|sum,num| sum + num}  
is  
sum2 = -\>(a,b) &sum  
valid syntax? Or is  
sum2 = -\>(a,b,&sum)  
correct?

Farrel

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [November 18, 2008, 10:51am UTC](https://www.ruby-forum.com/t/1-9-lambda-syntax-with/153519/2 "2008-11-18T10:51:42Z")

</div>

Farrel L. wrote:

> Given  
> sum = Proc.new{|sum,num| sum + num}  
> is  
> sum2 = -\>(a,b) &sum  
> valid syntax? Or is  
> sum2 = -\>(a,b,&sum)  
> correct?

It’s not clear to me what you’re trying to do.

If you are defining a lambda by means of an existing block, then that  
existing block will already have a parameter list, so you don’t specify  
it again. That is:

irb(main):001:0\> sum = Proc.new{|sum,num| sum + num}  
=\> #Proc:0x83a5a18@:1(irb)  
irb(main):002:0\> sum2 = lambda(&sum)  
=\> #Proc:0x83a5a18@:1(irb)  
irb(main):003:0\> sum2[3,4]  
=\> 7

It appears that the -\> syntax can’t be used here.

However, if you want to define a new lambda which takes a block as an  
argument, then you need to give a body for the new lambda.

irb(main):004:0\> sum2 = -\>(a,b,&foo) { foo[a,b] + 9 }  
=\> #\<Proc:0x838310c@(irb):4 (lambda)\>  
irb(main):005:0\> sum2[3,4,&sum]  
=\> 16
