---
title: "SICP 1.32 答案"
author: "t0uch"
date: "2009-11-13T14:37:47Z"
tags: []
slug: "sicp-1-32"
draft: false
lastmod: "2009-11-13T14:37:47Z"
id: 516457
url: "https://t0uch.iteye.com/blog/516457"
---

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

```scheme
(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))))
```


迭代版

```scheme
(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))
```