In the documentation for fold, it says
Fold[f,x,list] gives the last element of FoldList[f,x,list].
But this is surely not the way it is implemented, right? In those cases where each step of the Fold
returns a large object, it would be a huge waste of memory to actually store the whole list and then just pick the last element at the end.
How can I test this? Does Trace
work as advertised, or does it skip printing intermediate steps sometimes?
TracePrint[Fold[f, a, Range[4]]]
. $\endgroup$