Article View: comp.lang.clos
Article #13Avoiding CLASS-PROTOTYPE
From: Len Charest
Date: Mon, 02 Nov 1992 21:46
Date: Mon, 02 Nov 1992 21:46
33 lines
2152 bytes
2152 bytes
Problem: given a metaclass CACHING-CLASS that maintains a list of all its direct
instances, how can I create and use a CLASS-PROTOTYPE for a class based on
CACHING-CLASS and also, as a special case, ensure that the CLASS-PROTOTYPE does not
appear in the metaclass instance list?
I use the following implementation of CACHING-CLASS to maintain a list of all
instances of a class whose metaclass is CACHING-CLASS. (AMOP gives a related
example of a metaclass named COUNTED-CLASS on pp. 72-74)
;;; define a metaclass 'caching-class' which maintains a list
;;; of all direct instances of the class; the instances may be
;;; retrieved and mapped over; instances are stored on the class
;;; object, not on a shared slot
(defclass caching-class (standard-class)
((direct-instances :accessor class-direct-instances
:initform nil)))
;;; automatically record instance creation on any class that uses
;;; caching-class as a metaclass
(defmethod make-instance :around ((class caching-class) &rest initargs)
(let ((instance (call-next-method)))
(push instance (class-direct-instances class))
instance))
The problem with this implementation is that its impossible to know a priori
whether the instance being created in MAKE-INSTANCE is a class prototype or a
'normal' instance to be pushed on the list of CLASS-DIRECT-INSTANCES.
Any ideas. I'm using LUCID 4.0.2.
..................................................
Len Charest, Jr.
JPL Artificial Intelligence Group
charest@aig.jpl.nasa.gov
Technical Details
Message-ID:
<1992Nov2.214651.18857@jpl-devvax.jpl.nasa.gov>Path:
arc1-ca.pugleaf.net!sparky!uunet!think.com!ames!elroy.jpl.nasa.gov!ufo!Aig.Jpl.Nasa.Gov!charestShow Full Headers
Complete Article Headers
Newsgroups: comp.lang.clos Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!ames!elroy.jpl.nasa.gov!ufo!Aig.Jpl.Nasa.Gov!charest From: charest@Aig.Jpl.Nasa.Gov (Len Charest) Subject: Avoiding CLASS-PROTOTYPE Message-ID: <1992Nov2.214651.18857@jpl-devvax.jpl.nasa.gov> Keywords: class prototype caching metaclass Sender: usenet@jpl-devvax.jpl.nasa.gov (For NNTP so rrn will be able to post) Nntp-Posting-Host: ai-cyclops Reply-To: charest@aig.jpl.nasa.gov Organization: NASA/Jet Propulsion Laboratory Date: Mon, 2 Nov 1992 21:46:51 GMT Lines: 33