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
The instanceof operator allows to check whether an object belongs to a certain class. It also takes inheritance into account.
The isinstance() method checks whether an object is an instance of a class whereas issubclass() method asks whether one class is a subclass of another class (or other classes).
Using instanceof operator, when a class extends a concrete class. When a class extends a concrete class, the instanceof operator returns true when a subclass object is checked against its concrete superclass-type.
Java instanceof Operator The instanceof operator in Java is used to check whether an object is an instance of a particular class or not. objectName instanceOf className; Here, if objectName is an instance of className , the operator returns true . Otherwise, it returns false .
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With