2008. 3. 17.

연습문제 1.32

a.

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

(define (product2 term a next b)
  (accumulate * 1 term a next b))

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


댓글 없음:

댓글 쓰기