Lecture overview -- Keyboard shortcut: 'u'  Previous page: A general pattern of classes -- Keyboard shortcut: 'p'  Next page: A general pattern of classes with inheritance -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Lecture 8 - Page 7 : 11
Functional Programming in Scheme
Object-oriented programming in Scheme
Example of the general class pattern

The Point class redefined to comply with the general class pattern

(define (point x y)
 (let ((x x) 
       (y y)
      )
     
   (define (getx) x)

   (define (gety) y)

   (define (add p) 
    (point 
     (+ x (send 'getx p))
     (+ y (send 'gety p))))

   (define (type-of) 'point)
     
   (define (self message)
     (cond ((eqv? message 'getx) getx)
           ((eqv? message 'gety) gety)
           ((eqv? message 'add)  add)
           ((eqv? message 'type-of) type-of)
	   (else (error "Undefined message" message))))
     
   self))

The class Point implemented with use of the general class template. The Point class corresponds to the Point class defined on an earlier page. Notice that the bindings of x and y in the let construct is superfluous in the example. But due to the simultaneous name binding used in let constructs, they make sense. Admittedly, however, the let construct looks a little strange.

y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/point-class-all.scmAll necessary stuff to play with Point.


y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/point-dialogueA sample construction and dialogue with point.