(defclass Boat1 () (position heading speed))
(defclass Boat () ((position :initform nil :initarg :pos :accessor boat-pos ) (heading :initform nil :initarg :heading :reader boat-heading ) (speed :initform 0 :initarg :speed :accessor boat-speed ) (windspeed :initarg :windspeed :accessor boat-windspeed :allocation :class ) ) )
(defmethod change-heading (c new-heading) (format t "You can't change the heading of this!") ) (defmethod change-heading ((c Boat) new-heading) (cond ((numberp new-heading) (setf (slot-value c 'windspeed) (mod new-heading 360)) ) ((equalp new-heading 'Dry-Dock) (setf (slot-value c 'windspeed) nil) ) (t (call-next-method)) ) )
(defclass aircraft-carrier (Boat) ((num-planes :initarg :num-planes :initform 16 :reader Boat-planes )) ) (defmethod launch ((b aircraft-carrier) on-orders-from) (if (> (Boat-planes b) 0) (setf (slot-value b 'num-planes) (- (Boat-planes b) 1)) ) ) (defmethod land ((b aircraft-carrier)) (setf (slot-value b 'num-planes) (+ (Boat-planes b) 1)) )
(defclass military-aircraft-carrier (aircraft-carrier)()) (defmethod launch ((b military-aircraft-carrier) on-orders-from) (if (equalp on-orders-from 'Admiral) (call-next-method) ) ) (defmethod launch :before ((b aircraft-carrier) on-orders-from) (do () ((>= (Boat-planes b) 5)) (land b) ) ) (defmethod launch :after ((b aircraft-carrier) on-orders-from) (format t "~%Planes launched, sir.~%") )