🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Thomas A. Russ Wed, 16 Dec 1992 00:19
Best way to set class slots
#561
Author: Thomas A. Russ
Date: Wed, 16 Dec 1992 00:19
18 lines
1009 bytes
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 the documentation indicates that setting slots
on the prototype is a no-no.

Currently I just make an instance, set the slot and then throw the
instance away.  This just strikes me as wasteful.

Any better ideas?

--

Thomas A. Russ                                             tar@isi.edu    
USC/ISI, 4676 Admiralty Way, Marina del Rey, CA 90292      (310) 822-1511
Re: Best way to set class slots
#567
Author: Len Charest
Date: Thu, 17 Dec 1992 22:12
37 lines
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
Re: Best way to set class slots
#569
Author: Harley Davis
Date: Fri, 18 Dec 1992 09:37
40 lines
1769 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 the documentation indicates that setting slots
   on the prototype is a no-no.

   Currently I just make an instance, set the slot and then throw the
   instance away.  This just strikes me as wasteful.

   Any better ideas?

If you want to set a slot given the class but without an instance,
perhaps what you really want is a class slot -- ie, a new metaclass
with an additional slot.

   (defclass my-class (standard-class)
     ((new-slot :initform ...
                :accessor my-class-new-slot)))

Then your application classes specify my-class as their metaclass:

   (defclass app-object ()
     (...)
     :metaclass my-class)

It depends on the semantics of the slot in question.

-- Harley Davis

--

------------------------------------------------------------------------------
nom: Harley Davis			ILOG S.A.
net: davis@ilog.fr			2 Avenue Gallie'ni, BP 85
tel: (33 1) 46 63 66 66			94253 Gentilly Cedex, France
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads