|
From: Hoehle, Joerg-C. <Joe...@t-...> - 2003-02-20 16:52:34
|
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.
|