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