Article View: comp.lang.clos
Article #567Re: Best way to set class slots
From: Len Charest
Date: Thu, 17 Dec 1992 22:12
Date: Thu, 17 Dec 1992 22:12
37 lines
2229 bytes
2229 bytes
In article <23063@venera.isi.edu>, tar@ISI.EDU (Thomas A. Russ) writes:
|>
|> I was wondering what the best way to set a slot with allocation :class
|> is. In particular, I wonder if there is any way to do this portably
|> without creating an instance of the class.
|>
|> Initially I thought that using the CLASS-PROTOTYPE from the MOP would
|> be a good solution,
But isn't CLASS-PROTOTYPE technically an instance of the class? You may want to
try defining a subclass of STANDARD-CLASS and storing your information on a slot
of the subclass. Then the 'shared' slot would be available
even if no instances were ever created. If instances were created then they could
access they class object for the shared information; you could hide this
implementation with a custom method or with a method on SLOT-VALUE-USING-CLASS to
maintain the illusion of a shared slot:
(defclass alien-class (standard-class)
((collective-conscious :initform nil)))
(defclass martian ()
((sex :type (member :foo :bar :baz)))
(:metaclass alien-class)) ;a subclass of standard-class!
;;; custom retrieval
(defmethod martian-collective-conscious ((m martian))
(slot-value (class-of m) 'collective-conscious))
;;; slot-value illusion
(defmethod slot-value-using-class ((c alien-class) obj
(slot (eql 'collective-conscious)))
(declare (ignore obj))
(slot-value c 'collective-conscious))
..................................................
Len Charest, Jr.
JPL Artificial Intelligence Group
charest@aig.jpl.nasa.gov
Technical Details
Message-ID:
<1992Dec17.221226.25032@jpl-devvax.jpl.nasa.gov>Path:
arc1-ca.pugleaf.net!sparky!uunet!olivea!spool.mu.edu!sdd.hp.com!elroy.jpl.nasa.gov!jato!ufo!Aig.Jpl.Nasa.Gov!charestReferences:
<23063@venera.isi.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!spool.mu.edu!sdd.hp.com!elroy.jpl.nasa.gov!jato!ufo!Aig.Jpl.Nasa.Gov!charest From: charest@Aig.Jpl.Nasa.Gov (Len Charest) Newsgroups: comp.lang.clos Subject: Re: Best way to set class slots Message-ID: <1992Dec17.221226.25032@jpl-devvax.jpl.nasa.gov> Date: 17 Dec 92 22:12:26 GMT References: <23063@venera.isi.edu> Sender: usenet@jpl-devvax.jpl.nasa.gov (For NNTP so rrn will be able to post) Reply-To: charest@aig.jpl.nasa.gov Distribution: comp Organization: NASA/Jet Propulsion Laboratory Lines: 37 Nntp-Posting-Host: ai-cyclops