#! /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)