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'  Help page about these notes  Alphabetic index  Course home  Lecture 3 - Page 5 : 43
Programming Paradigms
Simulation of other Paradigms and Continuations
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 "Message not understood" 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.

c:/Users/Kurt/Teaching-material/Pp-Scheme-17/notes/includes/point-class-all.scmAll the necessary stuff to play with Point.


c:/Users/Kurt/Teaching-material/Pp-Scheme-17/notes/includes/point-dialogueA sample construction and dialogue with point.