[an error occurred while processing this directive]

cs150: Notes 22

Assignments Due

Notes

(define (make-counter)
   ((lambda (count)
      (lambda ()
        (set! count (+ 1 count))
        count))
   0))
Draw the environment after:
   (define counter (make-counter))
   (counter)









(define (make-counter)
   (let ((count 0))
     (lambda (message)
       (cond ((eq? message 'reset!)  (set! count 0))
	     ((eq? message 'next!)   (set! count (+ 1 count)))
	     ((eq? message 'current) count)
	     (else (error "Unrecognized message"))))))
What is an object?





Why is it useful to package state and procedures together?




[an error occurred while processing this directive]