ITeye博客

SICP 1.32 答案

t0uch · 2009-11-13 14:37 · SICP · Markdown

从之前写好的代码可以很容易写出

递归版

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

迭代版

(define (accumulate combiner null-value term a next b)
  (define (iter a result)
    (if (> a b)
        result
        (iter (next a) (combiner (term a) result))))
  (iter a null-value))

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。