[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: syntax sugar: treating an object like a method

Eric Mahurin

5/19/2005 12:39:00 PM

> >> Another note: as far as I remember there are plans to make
> ()
> >> work for
> >> lambdas. So currently we have
> >>
> >>>> f = lambda {|x| x+x}
> >> => #<Proc:0x100c3e60@(irb):15>
> >>>> f[10]
> >> => 20
> >>>> f.call 10
> >> => 20
> >>
> >> Then we had additionally
> >>
> >>>> f(10)
> >> => 20
> >
> > Cool. So, this sounds like the ()/null operator is being
> > implemented with procs/lambdas. Now if we could just have
> it
> > for the rest of the objects.
>
> It'll probably work as general mapping to #call so it would
> work with
> everything that has #call.
>
> Cheers
>
> robert

Thanks Robert. If that is the case, it sounds like I'll get
the main thing I wanted - ()/null operator.

Anybody know if lambdas will also support blocks anytime soon?
It doesn't seem to make sense why I can't do this:

f = lambda {|*args,&block|puts(*args);block[]}
f[1,2,3] { puts("hi") }

or in the 1.9 syntax:

f = {|*args,&block|puts(*args);block[]}
f(1,2,3) { puts("hi") }

I just grabbed 1.9 and none of this new syntax seems to work.




Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mai...



1 Answer

Christian Neukirchen

5/19/2005 2:36:00 PM

0

Eric Mahurin <eric_mahurin@yahoo.com> writes:

> Anybody know if lambdas will also support blocks anytime soon?
> It doesn't seem to make sense why I can't do this:
>
> f = lambda {|*args,&block|puts(*args);block[]}
> f[1,2,3] { puts("hi") }
>
> or in the 1.9 syntax:
>
> f = {|*args,&block|puts(*args);block[]}
> f(1,2,3) { puts("hi") }
>
> I just grabbed 1.9 and none of this new syntax seems to work.

Blocks should be able to take blocks since 1.9. I tried that not too
long ago.

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...