From: "Ara.T.Howard" Date: 2005-10-20T04:12:08+09:00 Subject: Re: Functional with Ruby On Thu, 20 Oct 2005, Andreas Semt wrote: > Hello list, > > here a really simple Haskell function, which sums all elements of a list > (from the book "The Haskell School of Expression"): > -------------------------------- > listSum [] = 0 > listSum (x : xs) = x + listSum xs > -------------------------------- > > Which is the best way to say it in Ruby (functional style)? Don't use > 'enum.inject', please! harp:~ > cat a.rb list_sum = lambda{|*list| list.flatten!; list.empty? ? 0 : list.shift + list_sum[list] } p list_sum[ 0b101000, 0b10 ] harp:~ > ruby a.rb 42 -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | anything that contradicts experience and logic should be abandoned. | -- h.h. the 14th dalai lama ===============================================================================