From: Steven Lumos Date: 2007-03-27T08:58:54+09:00 Subject: Re: Backus, Functional Programming, and Ruby Devin Mullins writes: > Jesse Merriman wrote: >> On Sunday 25 March 2007 18:03, Joel VanderWerf wrote: >> >>>Ruby has its own way of doing things, not that there is anything wrong >>>with defining new ways: >>> >>>[[1,2,3], [6,5,4]].transpose.map{|x,y|x*y}.inject{|s,x|s+x} >>>=> 28 >> >> Yep, I was just seeing how close I could make Ruby code look like >> Backus' code; the goal was to define inner_product as a compose of >> the three other functions without any named variables. > > module Enumerable > def inner_product > transpose.map(&:*).inject(&:+) > end > end > > :P > > (Not to slight Backus. Functional programming and BNF are both totally > cool.) That's the most morphologically equivalent to Lisp Ruby ever! (defun inner_product (matrix) (reduce '+ (mapcar '* (transpose matrix)))) I'm rusty, but still... Steve