Menu

Class 4: List processing in scheme


Reading
To Appear.

Homework
Prepare for the first practicum Quiz. Make sure every lab and homework problem so far makes sense to you! See me if something doesn't. Most of all, take the Practice Practicum, giving yourself no more than 50 minutes to get both functions working perfectly.

Homework Review
Here are solutions to the lab problems I asked you turn in as homework. Get used to recursion in scheme, because that's how you get everything done!
;#####################################################################
;## PROBLEM 1 
;#####################################################################
(define (factorial n) (if (= n 0) 1 (* n (factorial (- n 1)))))

;#####################################################################
;## PROBLEM 2
;#####################################################################
;; compound-month B r: returns balance after 1 month of compounding
(define (compound-month B r) (* B (+ 1 (/ r 1200.0))))

;; compound-months B r m: returns balance after m months of compounding
(define (compound-months B r m) 
  (if (= m 0) 
      B 
      (compound-months (compound-month B r) r (- m 1))))

;; accrue B r y: returns balance after y years of monthly compounding
(define (accrue B r y) (compound-months B r (* y 12)))

;#####################################################################
;## PROBLEM 3
;#####################################################################
(define (fib n) (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2)))))
	
Lists
We talked all about lists in Scheme. Note: Lists are really, really important in Scheme!
Lab 2
With all your new-found list knowledge, it's time to get started on Lab 2!


Christopher W Brown
Last modified: Tue Jan 17 16:51:54 EST 2006