On Tue, Mar 11, 2014 at 03:47:53PM +0100, Daniel Carrera wrote: > On 11 March 2014 15:41, Peter Bex <peter....@xs4all.nl> wrote: > > > To avoid such mistakes, it's helpful to use mnemonic names: > > > > (fold (lambda (item result) (+ (* result 10) item)) 0 '(1 2 3)) > > > > > Thanks. I was mentally reading from left to right, so I ended up assuming > that it was (result item).
That would make more sense, I guess, and is the ordering used by other functional languages. There's a built-in version of fold which obeys this ordering, called foldl: http://api.call-cc.org/doc/library/foldl I think SRFI-1's FOLD uses the oher way around is because of the notion that the procedure argument is called a CONStructor, and "cons" accepts the item first and the list on which to cons second, making "reverse" trivial to implement like this: (fold cons '() '(1 2 3 4)) => (4 3 2 1) I find it's easy enough to remember if you keep this in mind. Cheers, Peter -- http://www.more-magic.net _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users