(define (accumulate a b combiner null-value term next)
(if (> a b)
null-value
(combiner (term a)
(accumulate (next a) b combiner null-value term next))))
(define (accumulate-iter a b combiner null-value term next)
(define (iter a result)
(if (> a b)
result
(iter (next a) (combiner result
(term a)))))
(iter a null-value))
(define (sum a b term next)
(accumulate a b + 0 term next))
(define (product a b term next)
(accumulate a b * 1 term next))
(define (sum-iter a b term next)
(accumulate-iter a b + 0 term next))
(define (product-iter a b term next)
(accumulate-iter a b * 1 term next))
(define (identity n) n)
(define (inc n) (+ n 1))
(display (sum 1 10 identity inc))
(newline)
(display (sum-iter 1 10 identity inc))
(newline)
(display (product 1 10 identity inc))
(newline)
(display (product-iter 1 10 identity inc))
(newline)
KGRlZmluZSAoYWNjdW11bGF0ZSBhIGIgY29tYmluZXIgbnVsbC12YWx1ZSB0ZXJtIG5leHQpCgkoaWYgKD4gYSBiKQoJCW51bGwtdmFsdWUKCQkoY29tYmluZXIgKHRlcm0gYSkKCQkJICAoYWNjdW11bGF0ZSAobmV4dCBhKSBiIGNvbWJpbmVyIG51bGwtdmFsdWUgdGVybSBuZXh0KSkpKQoKKGRlZmluZSAoYWNjdW11bGF0ZS1pdGVyIGEgYiBjb21iaW5lciBudWxsLXZhbHVlIHRlcm0gbmV4dCkKCQkoZGVmaW5lIChpdGVyIGEgcmVzdWx0KQoJCQkoaWYgKD4gYSBiKQoJCQkJcmVzdWx0CgkJCQkoaXRlciAobmV4dCBhKSAoY29tYmluZXIgcmVzdWx0CgkJCQkJCQkgKHRlcm0gYSkpKSkpCgkJKGl0ZXIgYSBudWxsLXZhbHVlKSkKCihkZWZpbmUgKHN1bSBhIGIgdGVybSBuZXh0KQoJKGFjY3VtdWxhdGUgYSBiICsgMCB0ZXJtIG5leHQpKQoKKGRlZmluZSAocHJvZHVjdCBhIGIgdGVybSBuZXh0KQoJKGFjY3VtdWxhdGUgYSBiICogMSB0ZXJtIG5leHQpKQoKKGRlZmluZSAoc3VtLWl0ZXIgYSBiIHRlcm0gbmV4dCkKC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