More Solution to problem 6B 

Forum: Com Sci 12500, U Chicago, Autumn 2002, Discuss Classwork
Re: News Final Exam Posted (Dan Hirschberg)
Date: 2002, Dec 11
From: Mike O'Donnell <odonnell@cs.uchicago.edu>

I was thinking of this


(define (make_increment)

  (let ((history '()))

     (lambda (n)

        (if (integer? n)

            (begin

              (set! history (append history (list n)))

              (+ n 1))

             history))))

(define increment (make_increment))
But two brilliant people saw the more elegant form:

(define increment

 (let ((history '()))

     (lambda (n)

        (if (integer? n)

            (begin

              (set! history (append history (list n)))

              (+ n 1))

             history))))
It makes perfect logical sense, and it works (I tested it). I don't remember seeing this form in the text, but maybe I overlooked it.


to: "Solution to problem 6B"