(define (accumulate op initial sequence)
(if (null? sequence)
initial
(op (car sequence)
(accumulate op initial (cdr sequence)))))
(define (filter predicate sequense)
(cond ((null? sequense) '())
((predicate (car sequense))
(cons (car sequense)
(filter predicate (cdr sequense))))
(else (filter predicate (cdr sequense)))))
(define (acc-map f tree)
(accumulate cons '() tree))
(define (acc-length tree)
(accumulate (lambda (x y) (+ 1 y)) tree))
(define (fringe tree)
(cond ((null? tree) '())
((not (pair? tree)) (list tree))
(else (append (fringe (car tree))
(fringe (cdr tree))))))
(define (enumerate-interval low high)
(if (> low high)
'()
(cons low (enumerate-interval (+ low 1) high))))
(define (acc-sum list)
(accumulate + 0 list))
(define (count-leaves t)
(accumulate (lambda (x y) (+ 1 y)) 0 (fringe t)))
(define (accumulate-n op init seqs)
(if (null? (car seqs))
'()
(cons (accumulate op init (map car seqs))
(accumulate-n op init (map cdr seqs)))))
(define s '((1 2 3) (4 5 6) (7 8 9) (10 11 12)))
(define ei enumerate-interval)
(define m2.37 (list (ei 1 4) (append (ei 4 6) '(6)) (ei 6 9)))
(define (dot-product v w)
(accumulate + 0 (map * v w)))