All necessary stuff to play with Point. | Lecture 8 - slide 5 : 11 Program 2 |
(define (send message obj . par) (let ((method (obj message))) (apply method par))) (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"))))))