University of Virginia, Department of Computer Science
CS200: Computer Science, Spring 2002

Notes: Friday 8 March 2002
Schedule

Notes
(define (make-number n)
  (lambda (message)
    (cond
     ((eq? message 'value) (lambda (self) n))
     ((eq? message 'add) (lambda (self other)
			   (+ (ask self 'value) (ask other 'value))))))))

(define (ask object message . args) (apply (object message) object args))
Inheritance is using the definition of one class to make another class.
(define (make-fraction numer denom)
  (let ((super (make-number #f)))
    (lambda (message)
      (cond
       ((eq? message 'value) (lambda (self) (/ numer denom)))
       ((eq? message 'get-denominator) (lambda (self) denom))
       ((eq? message 'get-numerator) (lambda (self) numer))
       (else (super message))))))
The class fraction inherits from number.
fraction is a subclass of number.
The superclass of fraction is number.

Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

Byrd's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.


CS 655 University of Virginia
Department of Computer Science
CS 200: Computer Science
David Evans
evans@virginia.edu
Using these Materials