fold-left takes arguments like
(fold-left function init list)and computes
* (fold-left (lambda (l r) `(f ,l ,r)) 'init '(a b c)) (F (F (F INIT A) B) C)Notice how
initis the leftmost of all the arguments to the function, and each argument appears left to right as it is folded in.
Now look at the usual way
(fold-right function init list)It computes
* (fold-right (lambda (l r) `(f ,l ,r)) 'init '(a b c)) (F A (F B (F C INIT)))although
initappears first and to the left of
'(a b c)in the arguments to
fold-right, it is actually used as the rightmost argument to the last application.
It seems to me that the arguments to
be in this order:
; (fold-right function list final) * (fold-right (lambda (l r) `(f ,l ,r)) '(a b c) 'final) (F A (F B (F C FINAL)))The argument lists to
fold-rightwould no longer match, but I think switching things around so that the anti-symmetry of the arguments matches the anti-symmetry of the folding makes things clearer.