(define (tree-accumulate tree term combiner null-value)
  (cond ((null? tree) null-value)
        ((pair? tree)
         (combiner
           (tree-accumulate (car tree) term combiner null-value)
           (tree-accumulate (cdr tree) term combiner null-value)))
        (else (term tree))))