Jasper wrote:Isn't that just untrue?what iterate doc about higher order functions wrote:One problem with higher-order functions is that they are inefficient, requiring multiple calls on their argument function. While the the built-ins, like map and mapcar, can be open-coded, that cannot be so easily done for user-written functions. Also, using higher-order functions often results in the creation of intermediate sequences that could be avoided if the iteration were written out explicitly.
Why do you think that this statement is not true?
Consider the following:
- Code: Select all
(reduce '+ (mapcar (lambda (x) (* x 2)) '(1 2 3 4)))
mapcar creates a new, freshly consed list. This list is the passed to reduce. But this fresh list is not neccessary, because it is possible to reduce this list in-place.
In Haskell, this statement about higher-order functions would be completely true: compiler would rearrange code to prevent unnecessary allocation of intermediate lists (this is called «list fusion»).
