Due April 30, 1998 before class

Read a Scheme reference and Chapter 8 in the EOPL book.

Write Scheme definitions for the following functions and convert them to CPS. The continuation argument should be the last argument. For example, if you were asked to write factorial and its CPS counterpart, the answer would be:

(define fact
  (lambda (n) 
    (if (zero? n)
        1
        (* n (fact (- n 1))))))

(define factcps
  (lambda (n k)
    (if (zero? n)
        (k 1)
        (factcps (- n 1) (lambda (v)
          (k (* n v)))))))

Extra Credit

Write a Scheme procedure that does part of the homework for you. Yes, the conversion to CPS could be automated.
Page visited times since November 18, 1996.

sabry@cs.uoregon.edu