假设我有如下代码设置
(defgeneric move (ship destination))
(defmethod move (ship destination)
;; do some fuel calculation here
)
(defmethod move :after ((ship ship) (dest station))
;; do things specific to landing on a station here
)
(defmethod move :after ((ship ship) (dest planet))
;; do things specific to landing on a planet here
)
现在假设我想将我的宇宙飞船移动到一个站点,但燃料计算导致飞船上的燃料量为负数(即没有足够的燃料用于旅行)。
那么有没有办法让我防止:after
限定符被调用而不必发出错误信号?
如果我不停止通话,船将被移动到新位置而不会减去任何燃料,这基本上会破坏游戏。