From: Joel VanderWerf Date: 2009-01-12T12:14:15+09:00 Subject: Re: functional programming Mike Gold wrote: > Joel VanderWerf wrote: >> Mike Gold wrote: >>> data = [[1,2,3], [4,5,6,7]] >>> 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] > > Sure, you can solve a different problem than the one I gave. > But the original problem remains. We cannot, in general, modify > 'mean'. > > Do you propose to change every method in the ruby standard library > to take just one argument--an array? That would work. Sounds like > Lisp. Sorry, I may not have followed the discussion very well. But it seems more natural in this specific case to define mean to take one array argument, rather than *args, since (or so I imagine), that's usually how input will arrive. How often do you write code like x = ... y = ... z = ... m = mean.call( x,y,z ) as opposed to a = ... m = mean.call( a ) ? Perhaps I'm distracted by the specifics of mean and missing the general point... -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407