Topics to know:

Below is code from review during class

(require (lib "trace.ss"))  ; for testing only
(define (square x) (* x x))
(define (1+ x) (+ x 1))
(define (2+ x) (+ x 2))
(define (identity x) x)


(define (acc2 combiner id term a next b)
  (acc-iter combiner id term a next b))
(define (acc-iter combiner result term a next b)
  (cond ((> a b) result)
        (else (acc-iter combiner 
                        (combiner (term a) result)
                        term
                        (next a)
                        next 
                        b))))

; (trace acc-iter)
; (trace accumulate)

(define (double f)
  (lambda (x) (f (f x))))

;(double 1+) --> (lambda (x) (1+ (1+ x)))
;(double double) --> (lambda (x) (double (double x)))
;(double (double double)) -->
  ; (lambda (x) ((double double) ((double double) x)))   
;(define (f g)  
;  (g 2))

; f(g(x))
(define (compose f g)
  (lambda (x) (f (g x))))
; repeated (two different ways)
(define (repeated f n)
  (lambda (x)
    (cond ((= n 0) x)
          (else ((compose f (repeated f (- n 1))) x)))))

(define (repeated f n)
  (lambda (x)
    (cond ((= n 0) x)
          (else ((repeated f (- n 1)) (f x))))))


; pi/4: product, pi-term
(define (accumulate combiner id term a next b)
  (cond ((> a b) id)
        (else (combiner (term a)
                        (accumulate combiner id term (next a) next b)))))

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

(define (pi-term n)
  (cond ((odd? n) (/ (+ n 1) (+ n 2)))
        (else (/ (+ n 2) (+ n 1)))))

(define (pi/4 terms)
  (product pi-term 1 1+ terms))

(define (pi terms)   ; Floating point nice for display purposes
  (* 4. (pi/4 terms)))

; An interval abstraction
(define make-interval cons)
(define lower car)
(define upper cdr)

; Another interval abstraction
(define (make-interval lower upper)
  (lambda (msg)
    (cond ((eq? msg 0) lower)
          ((eq? msg 1) upper))))
(define (lower interval) (interval 0))
(define (upper interval) (interval 1))

; Bottom line: Use lower and upper.  They work.  No guarantees about
;   how they are written though!