Equivalance of instanceof for CLOS? How to check if instance is inherited from another object?
Asked Answered
G

1

6
CL-USER> (defclass a () ())
CL-USER> (defclass b (a) ())
CL-USER> (make-instance 'b)
#<STANDARD-CLASS B>

What predicate function can I call on my instance b, which returns T if it was inherited from a? In the vein of:

CL-USER> (instanceof 'a *)
T
Granulation answered 3/10, 2013 at 5:38 Comment(0)
P
9

Class names are also type names, so:

(typep * 'a)

See Integrating Types and Classes: http://clhs.lisp.se/Body/04_cg.htm

Or you could do this:

(defmethod is-an-a-p ((x a))
  t)
(defmethod is-an-a-p ((x t))
  nil)
Pella answered 3/10, 2013 at 6:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.