sicp 1.33

(define (filtered-accumulate satisfied? combiner null-value term a next b)
  (if (> a b)
      null-value
      (if (satisfied? a)
          (combiner (term a)
                (accumulate combiner null-value term (next a) next b))
          (combiner null-value
                (accumulate combiner null-value term (next a) next b)))))

(filtered-accumulate prime? + 0 (lambda (x) x) a (lambda (x) (+ x 1)) b)

(filtered-accumulate coprime-n? * 1 (lambda (x) x) 1 (lambda (x) (+ x 1)) n)
 

你可能感兴趣的:(SICP)