Is there a simple way to test if a bound variable is a certan CLOS class?
In other words, if I use this silly example:
(defclass my-class1 ()
((prop1 :accessor prop1 :initform NIL)
(prop2 :accessor prop2 :initform NIL)))
(defclass my-class2 ()
((prop1 :accessor prop1 :initform NIL)
(prop2 :accessor prop2 :initform NIL)))
(defparameter *object* (make-instance 'my-class1))
I'm looking for something like this:
(print (my-class1-p *object*))
--jeff cunningham
Jeff Cunningham wrote:
> Is there a simple way to test if a bound variable is a certan CLOS class?
> In other words, if I use this silly example:
>
> (defclass my-class1 ()
> ((prop1 :accessor prop1 :initform NIL)
> (prop2 :accessor prop2 :initform NIL)))
>
> (defclass my-class2 ()
> ((prop1 :accessor prop1 :initform NIL)
> (prop2 :accessor prop2 :initform NIL)))
>
>
> (defparameter *object* (make-instance 'my-class1))
>
>
> I'm looking for something like this:
>
> (print (my-class1-p *object*))
Do you want to know if it's a instance of that class, or
of that class or a subclass?
For the first:
(eq (class-of *object*) (find-class 'my-class1))
For the second:
(typep *object* 'my-class1)
or
(typep *object* (find-class 'my-class1))
Paul
On Thu, 01 Sep 2005 20:51:07 -0500, Paul F. Dietz wrote:
> Jeff Cunningham wrote:
>> Is there a simple way to test if a bound variable is a certan CLOS class?
>> In other words, if I use this silly example:
>>
>> (defclass my-class1 ()
>> ((prop1 :accessor prop1 :initform NIL)
>> (prop2 :accessor prop2 :initform NIL)))
>>
>> (defclass my-class2 ()
>> ((prop1 :accessor prop1 :initform NIL)
>> (prop2 :accessor prop2 :initform NIL)))
>>
>>
>> (defparameter *object* (make-instance 'my-class1))
>>
>>
>> I'm looking for something like this:
>>
>> (print (my-class1-p *object*))
>
> Do you want to know if it's a instance of that class, or
> of that class or a subclass?
>
> For the first:
>
> (eq (class-of *object*) (find-class 'my-class1))
>
> For the second:
>
> (typep *object* 'my-class1)
>
> or
>
> (typep *object* (find-class 'my-class1))
>
> Paul
I was looking for the former, but the latter is very useful as well.
Thanks!
--jeff