(define (point x y)
(letrec ((getx (lambda () x))
(gety (lambda () y))
(add (lambda (p)
(point
(+ x (send 'getx p))
(+ y (send 'gety p)))))
(type-of (lambda () 'point))
)
(lambda (message)
(cond ((eq? message 'getx) getx)
((eq? message 'gety) gety)
((eq? message 'add) add)
((eq? message 'type-of) type-of)
(else (error "Message not understood")))))) |
| | The definition of a 'class Point ' with methods getx , gety , add , and type-of . On this page we have also defined the syntactical convenience function send that sends a message to an object. In MzScheme, be sure that you define send before Point (such that send in the add method refers to our send , and not an already existing and unrelated definition of
the name send ).
|