University of Virginia Computer Science CS150: Computer Science, Fall 2005 (none) 14 October 2005

## CS150 Notes 22 (14 October 2005)

#### Upcoming Schedule

• Monday, 17 October: PS5
• Wednesday, 19 October, Marc Levoy, Digital Michaelangelo Project (Newcomb Hall, South Meeting Room, 2pm)
• Before Friday, 23 October: Read rest of GEB part I (Chapters 2-4 and 6-9, in addition to Chapters 1 and 5 you have already read). See the study guide questions on Notes 18. I recommend reading a chapter every few days rather than trying to read it all just before October 23.

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

(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.

Which of the traced applications are from fraction and which are from number?
```> (ask half 'add half)
| #f
| #f
| #f
| #f
| #t
| |(eq? value value)
| |#t
| 1/2
| |(eq? value value)
| |#t
| 1/2
|1
1
```

If I have seen further it is by standing on the shoulders of giants.
Isaac Newton (on inheritance?)

If I have not seen as far as others, it is because giants were standing on my shoulders.
Hal Abelson (on subtyping?)

"); print ( \$res[\$first] ) ; print (""); ?>