From: Florian Gilcher Date: 2009-11-28T16:49:58+09:00 Subject: Re: closures -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On a sidenote, Ruby 1.9 also has this cool function: f = ->(a,b){ a + b } c = f.curry b = c[1] where b is a partially applied function, with a bound to 1. b[6] #=> a + b = 7 then evaluates the whole function. Regards, Florian P.S.: I still think it should be called #schönfinkeln. On Nov 28, 2009, at 2:47 AM, Allen Lee wrote: > Hi Burlsm, > > I think the following is what you want: > > def make_adder(n) > lambda { |x| x + n } > end > > or the following new lambda syntax if you are using Ruby 1.9 or later: > > def make_adder(n) > ->(x) { x + n } > end > > Hope that helps. > > allenlooplee > > On Sat, Nov 28, 2009 at 2:10 PM, Burlsm > wrote: > >> hi >> >> i'm having a little trouble with closures and i'd like to know what >> the equivalent code for the canonical make-adder procedure would in >> ruby, >> >> in scheme it would be like >> >> (define (make-adder n) >> (lambda (x) (+ x n)) >> >> thanks in advance >> >> - -- Florian Gilcher smtp: flo@andersground.net jabber: Skade@jabber.ccc.de gpg: 533148E2 -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.12 (Darwin) iEYEARECAAYFAksQ1iEACgkQyLKU2FMxSOIX+QCeN3vFLd0m1dIkxo+limomEs1s 1KYAniQhUT/DlL73ON63DSX/FrVTVIgN =irHI -----END PGP SIGNATURE-----