[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dispatching methods on a class type
- To: info-mcl
- Subject: Re: dispatching methods on a class type
- From: grant@pentagon-gw.army.mil (Pete Grant)
- Date: 11 Oct 92 00:04:28 GMT
- Newsgroups: comp.lang.lisp.mcl
- Organization: U.S. Army Artificial Intelligence Center, The Pentagon
- References: <9210020306.AA19613@taarna>
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.