[plt-scheme] what is fold-left?
On Wed, Feb 11, 2009 at 7:41 PM, Eli Barzilay <eli at barzilay.org> wrote:
> 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))
That's why I said in the text right after the post
``Also note that your version of Scheme might take the
arguments to fold-left in a different order.''
--
~jrm