From: William James Date: 2009-01-12T09:24:24+09:00 Subject: Re: functional programming Joel VanderWerf wrote: > Mike Gold wrote: > > Brian Candler wrote: > >> (2) to understand Mike's assertion > >> that Ruby lambdas are not first-class functions (i.e. "The > difference >> between lambda { } and a real first-class function is > quite profound"). > > > > Ruby: > > > > mean = lambda { |*args| > > (args.inject(0) { |acc, x| acc + x })/args.size.to_f > > } > > data = [[1,2,3], [4,5,6,7]] > > > > data.map(&mean) # fail > > data.map(&:mean) # fail > > data.map { |*numbers| mean.call(*numbers) } # fail > > data.map { |numbers| mean.call(*numbers) } # phew, found it > > > > Haskell: > > > > map mean data > > > > On this example alone, I think my characterization of "quite > > profound" is justified. > > Why isn't this the ruby candidate for comparison: > > mean = lambda { |ary| > (ary.inject { |acc, x| acc + x })/ary.size.to_f > } > data.map(&mean) # => [2.0, 5.5] mean = proc{|a| a.inject{|s,x| s+x} / a.size.to_f } ==># data.map &mean ==>[2.0, 5.5]