CLOS Example: ship


(defclass ship ()
   ((latitude    :type real)
    (longitude   :type real)
    (x-velocity  :type real)
    (y-velocity  :type real)) )

(defmethod speed ((s ship))
  (with-slots (s)
    (sqrt (+ (expt x-velocity 2)
             (expt y-velocity 2))) ))

(defmethod speedup ((s ship))
  (with-slots (s)
     (setf x-velocity (* x-velocity 2))
     (setf y-velocity (* y-velocity 2))
     s ))

A ``virtual slot'' speed is defined whose value is computed. The method speedup is defined similarly.

Contents    Page-10    Prev    Next    Page+10    Index