#! /usr/bin/racket
(define (accumulate a b combiner null-value term next)
(if (> a b)
null-value
(combiner (term a)
(accumulate (next a) b 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))
(sum 1 10 identity inc)
(sum-iter 1 10 identity inc)
(product 1 10 identity inc)
(product-iter 1 10 identity inc)
IyEgL3Vzci9iaW4vcmFja2V0CgooZGVmaW5lIChhY2N1bXVsYXRlIGEgYiBjb21iaW5lciBudWxsLXZhbHVlIHRlcm0gbmV4dCkKCShpZiAoPiBhIGIpCgkJbnVsbC12YWx1ZQoJCShjb21iaW5lciAodGVybSBhKQoJCQkgIChhY2N1bXVsYXRlIChuZXh0IGEpIGIgbnVsbC12YWx1ZSB0ZXJtIG5leHQpKSkpCgooZGVmaW5lIChhY2N1bXVsYXRlLWl0ZXIgYSBiIGNvbWJpbmVyIG51bGwtdmFsdWUgdGVybSBuZXh0KQoJCShkZWZpbmUgKGl0ZXIgYSByZXN1bHQpCgkJCShpZiAoPiBhIGIpCgkJCQlyZXN1bHQKCQkJCShpdGVyIChuZXh0IGEpIChjb21iaW5lciByZXN1bHQKCQkJCQkJCSAodGVybSBhKSkpKSkKCQkoaXRlciBhIG51bGwtdmFsdWUpKQoKKGRlZmluZSAoc3VtIGEgYiB0ZXJtIG5leHQpCgkoYWNjdW11bGF0ZSBhIGIgKyAwIHRlcm0gbmV4dCkpCgooZGVmaW5lIChwcm9kdWN0IGEgYiB0ZXJtIG5leHQpCgkoYWNjdW11bGF0ZSBhIGIgKiAxIHRlcm0gbmV4dCkpCgooZGVmaW5lIChzdW0taXRlciBhIGIgdGVybSBuZXh0KQoJKGFjY3VtdWxhdG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