Search code examples
inheritancelispcommon-lispclos

Checking parent class of an object


I would like to know a way how to check if an object is of certain class, or derived from it. E.g.:

(defclass a nil
  nil)

(defclass b (a)
  nil)

(defparameter *foo* (make-instance 'b))

(my-function *foo* 'a) ; => t
(my-function *foo* 'b) ; => t

Alternatively, a function that returns list of all base classes for a given object (or class) would be also appreciated.


Solution

  • Use typep:

    CL-USER 4 > (typep *foo* 'a)
    T
    
    CL-USER 5 > (typep *foo* 'b)
    T