Note that of the examples given, only Perl 6 and Common Lisp do two things that help immensely simplify the result:
1. reference the built-in * operator directly, without having to wrap it in a lambda expression; 2. actually name the function "!" The Lisp version suffers from the lack of a built-in range constructor. On Wed, May 27, 2009 at 2:21 PM, Mark J. Reed <markjr...@gmail.com> wrote: > > In Haskell it may be called fold (well, foldl and foldr), but the concept > has has a variety of names. Two of the more common ones are "reduce" and > "inject"; I believe Perl6 chose "reduce" for consistency with the Perl5 > List::Util module. Common Lisp and Python also call it "reduce": > > (defun ! (n) > (reduce #'* (loop for i from 1 to n collecting i))) > > > def fact(n): > return reduce(lambda x,y: x*y, range(1,n+1)) > > > While Ruby calls it "inject". > > > def fact(n) > (1..n).inject { |x,y| x*y } > end > > > Perl 6 has a lot of functional features. IMO the nice thing about its > version of reduce is the way it's incorporated into the syntax as a > metaoperator. > > -- > Mark J. Reed <markjr...@gmail.com> > > > -- Mark J. Reed <markjr...@gmail.com>