[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dispatching methods on a class type



In article <9210020306.AA19613@taarna> taarna!kaveh%comback.UUCP@IRO.UMontreal.CA (Kaveh Kardan) writes:
>
>I am wondering if there is a way in clos of dispatching methods on a class
>itself, as opposed to instances of the class.
>

If I understand your question correctly, there's no system-provided
method to retrieve all instances of a class.  

One way to accomplish it is to use a global variable  and
define an automatic way to push each newly created object onto
the list.

Example:

(defvar *instances* nil)

(defmethod initialize-instance :after ((self foo) &key)
  (if (eql (class-name (class-of self)) 'foo)
    (push self *instances*)))

The class test is needed only if you have defined subclasses
of foo to keep them from being included.

Hope this helps.

Pete.