CLOS实例的等价性?如何检查实例是否从另一个对象继承?

mck*_*mck 6 inheritance common-lisp clos

CL-USER> (defclass a () ())
CL-USER> (defclass b (a) ())
CL-USER> (make-instance 'b)
#<STANDARD-CLASS B>
Run Code Online (Sandbox Code Playgroud)

我可以在我的实例b上调用什么谓词函数,如果它继承自?本着:

CL-USER> (instanceof 'a *)
T
Run Code Online (Sandbox Code Playgroud)

Lar*_*off 9

类名也是类型名,因此:

(typep * 'a)
Run Code Online (Sandbox Code Playgroud)

请参阅集成类型和类:http://clhs.lisp.se/Body/04_cg.htm

或者你可以这样做:

(defmethod is-an-a-p ((x a))
  t)
(defmethod is-an-a-p ((x t))
  nil)
Run Code Online (Sandbox Code Playgroud)