From: Jeff Cunningham
Subject: how to test object for class membership?
Date: 
Message-ID: <pan.2005.09.02.01.34.42.238138@cunningham.net>
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

From: Paul F. Dietz
Subject: Re: how to test object for class membership?
Date: 
Message-ID: <QdKdnT75AbiWLYreRVn-uQ@dls.net>
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
From: Jeff Cunningham
Subject: Re: how to test object for class membership?
Date: 
Message-ID: <pan.2005.09.02.14.21.34.523766@cunningham.net>
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