Get the latest tech news
Fold-... and Monoids
A blog about computers, functional languages, Lisp, and Scheme.
The walk through the list, the end test, and the accumulation of the result are all taken care of by the implementation of fold. This is unfortunate because it seems obvious to write(fold-left #’cons ’() ...) to accumulate a list, but that isn’t how it works. If we unroll the recursion in fold-left, and introduce a temp variable to hold the intermediate result, we see the following:
Or read this on Hacker News