[racket] question about foldl implementation

From: Will Kurt (wckurt at gmail.com)
Date: Fri Aug 13 19:27:23 EDT 2010

I just wanted to thank all of you for your insightful responses. This has
been very useful!
--Will K.

On Fri, Aug 13, 2010 at 3:21 PM, Will M. Farr <wmfarr at gmail.com> wrote:

> +1 from me, too.  I always have to check myself to remember that the foldl
> accumulator argument comes in on the *right*.  FWIW, OCaml also does it the
> Haskell way (foldl accumulator on the left, foldr accumulator on the right).
>
> This also makes the obvious many-argument version more efficient:
>
> (define (foldl kons knil . lists)
>  (if (ormap null? lists)
>    knil
>    (apply foldl kons (apply kons knil (map car lists)) (map cdr lists))))
>
> as opposed to
>
> (define (foldl* kons knil . lists)
>  (if (ormap null? lists)
>    knil
>    (apply foldl* kons (apply kons (append (map car lists) (list knil)))
> (map cdr lists))))
>
> The extra append is kinda annoying in the foldl* version....
>
> Will
>
> On Aug 13, 2010, at 4:18 PM, Matthias Felleisen wrote:
>
> >
> > I privately +1ed Joe, and I all supportive of introducing new folds and
> phasing out the old ones.
> >
> >
> > On Aug 13, 2010, at 4:04 PM, Sam Tobin-Hochstadt wrote:
> >
> >> On Fri, Aug 13, 2010 at 3:11 PM, Joe Marshall <jmarshall at alum.mit.edu>
> wrote:
> >>> It seems to me that the Haskell version is better.
> >>
> >> The Haskell ordering also has the advantage of fitting with the Typed
> >> Racket type system for variable-arity functions.
> >> --
> >> sam th
> >> samth at ccs.neu.edu
> >> _________________________________________________
> >> For list-related administrative tasks:
> >> http://lists.racket-lang.org/listinfo/users
> >
> > _________________________________________________
> >  For list-related administrative tasks:
> >  http://lists.racket-lang.org/listinfo/users
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100813/4dbad8d2/attachment.html>

Posted on the users mailing list.