🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.clos
Article #18

RE: Avoiding CLASS-PROTOTYPE (Attn: MOP gods)]

#18
From: Len Charest
Date: Wed, 04 Nov 1992 18:32
49 lines
2980 bytes
In article <9211041420.AA14863@verdi.iisd.sra.com>, peterson@sra.COM (Eric Peterson x7644) writes:
|> >>>>> On Tue, 3 Nov 1992 00:26:30 GMT, charest@ai-cyclops.jpl.nasa.gov (Len Charest) said
|>    Len> I use the generic function CLASS-DIRECT-INSTANCES to access
|>    Len> the instance list.  The following :AROUND method on
|>    Len> CLASS-PROTOTYPE solves the problem described above.
|> 
|>    Len> (defmethod class-prototype :around ((class caching-class))
|>    Len>   (let ((prototype (call-next-method)))
|>    Len>     (setf (class-direct-instances class)
|>    Len>           (delete prototype (class-direct-instances class) :test #'eq))
|>    Len>     prototype))

|> Since class instance prototypes have nothing but unbound slots, perhaps
|> the MOP should specify that class instance prototypes be created with
|> allocate-instance instead of using make-instance (as Lucid has done).

Lucid 4.0.2 *does* use MAKE-INSTANCE to create the class prototype. 

> (trace make-instance allocate-instance)
(MAKE-INSTANCE ALLOCATE-INSTANCE)
> (defclass test () ())
1 Enter MAKE-INSTANCE #<Standard-Class STANDARD-CLASS>
| 2 Enter ALLOCATE-INSTANCE #<Standard-Class STANDARD-CLASS>
| 2 Exit ALLOCATE-INSTANCE #<Standard-Class #<Unbound-Slot 61A>>
1 Exit MAKE-INSTANCE #<Standard-Class  #X1CE6F9E>
#<Standard-Class TEST>
> (clos:class-prototype *)
1 Enter MAKE-INSTANCE #<Standard-Class TEST>
| 2 Enter ALLOCATE-INSTANCE #<Standard-Class TEST>
| 2 Exit ALLOCATE-INSTANCE #<Test #X1D03256>
1 Exit MAKE-INSTANCE #<Test #X1D03256>
#<Test #X1D03256>

This behavior prevents me from writing the 'obvious' method for keeping class
prototype off of the instance list:

(defmethod make-instance :around ((class caching-class) &rest args)
  (let ((instance (call-next-method)))
    (unless (eq instance (clos:class-prototype class))
      (push instance (class-direct-instances class)))
    instance))

Because CLASS-PROTOTYPE and MAKE-INSTANCE are now mutually dependent, attempting
to make any instance of a class whose metaclass is CACHING-CLASS will cause an
infinite recursion.
..................................................
                                  Len Charest, Jr.
                 JPL Artificial Intelligence Group
                          charest@aig.jpl.nasa.gov
Technical Details
Message-ID: <1992Nov4.183247.6578@jpl-devvax.jpl.nasa.gov>
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!destroyer!gumby!wupost!sdd.hp.com!usc!elroy.jpl.nasa.gov!jato!ufo!Aig.Jpl.Nasa.Gov!charest
References: <1992Nov3.002630.23187@jpl-devvax.jpl.nasa.gov> <9211041420.AA14863@verdi.iisd.sra.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.clos
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!destroyer!gumby!wupost!sdd.hp.com!usc!elroy.jpl.nasa.gov!jato!ufo!Aig.Jpl.Nasa.Gov!charest
From: charest@Aig.Jpl.Nasa.Gov (Len Charest)
Subject: RE: Avoiding CLASS-PROTOTYPE (Attn: MOP gods)]
Message-ID: <1992Nov4.183247.6578@jpl-devvax.jpl.nasa.gov>
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
References: <1992Nov3.002630.23187@jpl-devvax.jpl.nasa.gov> <9211041420.AA14863@verdi.iisd.sra.com>
Date: Wed, 4 Nov 1992 18:32:47 GMT
Lines: 49