列表类型的 defmethod

defmethod with list type

在Common Lisp中是否可以定义一个“列表类型”的方法?

(defgeneric show (obj))

(defmethod show ((obj coordinate)) ;; Works
  ...)
(defmethod show ((obj [LIST OF coordinate])) ;; How to?
  ...)

您可以在 list 类型上编写方法,但不能在任意类型说明符上编写方法。来自超规格:

If parameter-specializer-name is a symbol it names a class; if it is a list, it is of the form (eql eql-specializer-form).

相关问题:Defmethod on Arbitrary Type Specifiers?

类似这样的内容可能适合您:

(defmethod show ((obj coordinate))
  ...)

(defmethod show ((obj null)))
(defmethod show ((obj cons))  ;; Or just loop it.
  (show (car obj))
  (show (cdr obj)))