(define (tree-fold f tree)
(if (pair? tree)
(apply f (car tree) (map (lambda (t) (tree-fold f t)) (cdr tree)))
(f tree)))
works for example with: (tree-fold + '(1 (2 2)(2 2))
-> 9
However if I want to use (tree-fold append '(1 (2 2)(2 2)))
,
I have to modify the tree-fold
with list
around (car tree)
,
which breaks it for +
.
Is there some mechanism that can be used in the tree-fold
definition that would make it work with both +
and append
?