On Wed, May 27, 2009 at 1:59 PM, Daniel Carrera <
daniel.carr...@theingots.org> wrote:
> Wow... That's a foldl! In a functional language, that would be called a
> fold.

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 }

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

Mark J. Reed <markjr...@gmail.com>

Reply via email to