对象:defclass / defgeneric / defmethod

ZOS 的类、实例与槽;泛型函数按参数类型分派,call-next-method 链到下一个方法。

(defclass point () ((x :initarg :x) (y :initarg :y)))
(def p (make-instance point :x 3 :y 4))
[(slot-value p :x) (slot-value p :y) (class-of p)]

泛型函数按参数类型分派;call-next-method 链到下一个方法。

(defgeneric area (shape))
(defmethod area ((s point)) (* (slot-value s :x) (slot-value s :y)))
(area p)