Subject: [clisp-list] CLOS: class-wide slots defined at compile-time?

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Thu Feb 20 08:53:10 2003

Hi,

Sam wrote:

>IIUC, you need what MOP calls a "class prototype".
>I.e.,
>(defclass foo ()
>  (bar :allocation :class))
>
>(setf (slot-value (class-prototype (find-class 'foo)) 'bar)
>      (lambda () ...))
>right?
Looks like this would do the job. I'll have to take the AMOP book out of the library again.

>(defun shared-slot (class slot)
>    (cond ((null slot-location) (error "no such slot"))
>(setf (shared-slot (find-class 'foo) 'bar) (lambda () ...))

>Does this solve your problem?
This would so, as far as CLOS is concerned. But I ran into another, non CLOS, but compile-time problem (see other mail).

>Should we export CLOS:SHARED-SLOT, CLOS:SHARED-SLOT-BOUNDP and
>CLOS:SHARED-SLOT-MAKUNBOUND?
Why not? Once you wrote them...
Hmm, better error messages are needed, which leads to the following thought.

>An alternative would be to add a class prototype (which would waste an
>instance for each class...)

The class-prototype hack(?) may be something
1) which integrates better with the rest of CLOS. E.g. I guess one can raise a slot-missing error (which needs an instance as the second argument). How to raise slot-missing from within the proposed shared-slot function?
2) which seems to be somewhat standard in CLOS (I guess from your wording), whereas SHARED-SLOT would be specific to CLISP.

>I don't thing we may extend SLOT-VALUE and friends like this:
>(SLOT-VALUE symbol slot) == (SHARED-SLOT (find-class symbol) slot)
SLOT-VALUE is a function, so I guess there's not much to be changed there or general performance will suffer. But I don't understand this ==.

Maybe a separate weak hash-table trick may allow to implement a singleton class-prototype for all classes for which one was requested without spending an extra slot on each class?
(defvar clos:*class-prototypes* (make-hash-table :Test #'eq :weak :keys))
; weak so as not to grow unnecessarily
(defun class-prototype (class)
  (check-type class 'standard-class)
  (or (gethash class *class-prototypes* nil)
      (setf (gethash class *class-prototypes)
            (make-weird-instance-full-of #<unbound> slots except for the shared ones or whatever-is-needed))))
Or maybe that class-prototype should not be an instance of its class (but of some other one). Would that be against programmer's expectations??

Regards,
	Jorg Hohle.

---

From: Sam Steingold <[email-masked]>
Date: Thu Feb 20 11:16:10 2003

> * In message <[email-masked]>
> * On the subject of "[clisp-list] CLOS: class-wide slots defined at compile-time?"
> * Sent on Thu, 20 Feb 2003 17:52:21 +0100
> * Honorable "Hoehle, Joerg-Cyril" <[email-masked]> writes:
>
> Sam wrote:
> 2) which seems to be somewhat standard in CLOS (I guess from your
> wording), whereas SHARED-SLOT would be specific to CLISP.

it's in MOP.

> Maybe a separate weak hash-table trick may allow to implement a
> singleton class-prototype for all classes for which one was requested
> without spending an extra slot on each class?

> Or maybe that class-prototype should not be an instance of its class
> (but of some other one). Would that be against programmer's
> expectations??

it's better to keep the prototype inside the CLASS struct.
class may be redefined &c.
we may create the prototype on demand.

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat8 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
MS DOS: Keyboard not found. Press F1 to continue.