[plt-scheme] what is fold-left?

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Feb 11 22:41:46 EST 2009

On Feb 11, Eli Barzilay wrote:
> 
> In increasing order of alias-ness:
> 
> (define (fold-left kons init list) (foldl kons init list))
> 
> or
> 
> (define (fold-left . args) (apply foldl args))
> 
> or
> 
> (define fold-left foldl)
> 
> or
> 
> (require (rename-in scheme/base [foldl fold-left]))

... and all of these are wrong...  Sorry, I forgot that there was an
incompatibility with the srfi/1 fold: to use PLT's `foldl' you need a
slightly different function in `foldl':

  (define (sum f list)
    (foldl (lambda (element sum) ; <- arguments are swapped
             (+ sum (f element)))
           0
           list))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.