A First Taste of Objects

The implementation of the queue interface on p. 67 is very similar to the implementation of an object, in the sense of object-oriented programming. It holds both data (fields) and procedures (methods).

In a similar style, implement a point interface. A point has two numeric fields, x and y. The methods needed are:

(create-point x y)
(get-x)
(get-y)
(distance-from-origin)
(move-x amount)
(move-y amount)
For example, the expression
(let ((p (create-point 6 3)))
  (let ((get-x (point-get-get-x-operation p))
        (get-y (point-get-get-y-operation p))
        (distance-from-origin
         (point-get-distance-from-origin-operation p))
        (move-x (point-get-move-x-operation p))
        (move-y (point-get-move-y-operation p)))
    (move-x -3)
    (move-y 1)
    (list (get-x) (get-y) (distance-from-origin))))
should return the list (3 4 5).
Last modified: Fri Mar 26 11:24:01 PST 2004