[plt-scheme] what is fold-left?

From: Mike Eggleston (mikeegg1 at me.com)
Date: Wed Feb 11 22:48:46 EST 2009

On Wed, 11 Feb 2009, Eli Barzilay might have said:

> 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))

Great, thank you. Now I get the fun of figuring out just what the code does!

Mike


Posted on the users mailing list.