From: Christian Lynbech
Subject: Making a virtual slots metaclass
Date: 
Message-ID: <87k8kgwrri.fsf@tbit.dk>
I am trying to create a new metaclass that supports virtual slots, as
in the following:

        (defclass test () 
           ((a1 :initform 4)     
            (a2 :allocation :virtual :slot-ref (lambda (o) ...)
                                     :slot-set! (lambda (o v) ...))))

so a virtual slot is one where access is defined using two functions,
one for reading and one for writing.

My idea is to fiddle with compute-effective-slot-definition and
slot-value-using-class (and friends) to change the virtual slot into a
class slot holding a pair of the two access functions.

My first question is how to get the extended slot definition past the
creation of the slot-definition-meta-object. Both ACL and CMUCL
complains with errors such as (from ACL)

Error: :SLOT-REF are invalid initargs to make-instance of class
       #<STANDARD-CLASS CLOS:STANDARD-DIRECT-SLOT-DEFINITION>. The
       valid initargs are :CLASS CLOS::FIXED-INDEX :WRITERS :READERS
       :DOCUMENTATION :TYPE :ALLOCATION :INITARGS :INITFUNCTION :NAME
       :INITFORM.
  [condition type: PROGRAM-ERROR]

indicating that it considers :slot-ref an initarg for the
make-instance of the slot definition object.

This is in contrast to closette.lisp (in AMOP) where a comment says

;;; N.B. Quietly retain all unknown slot options (rather than
;;; signaling an error), so that it's easy to add new ones.


How can I teach ACL (or CMUCL) about new slot options?

PS
For the interested: I am trying to backport some goops code to CL for
a comparison. Goops is the OO extension of guile (a scheme) which has
descended from STk (another scheme) which has its OO from tiny-clos,
(Gregor Kiczales port of closette.lisp to scheme).


---------------------------+--------------------------------------------------
Christian Lynbech          | Ericsson Telebit A/S                       
Fax:   +45 8628 8186       | Fabrikvej 11, DK-8260 Viby J
Phone: +45 8738 2228       | email: ···@tbit.dk --- URL: http://www.tbit.dk
---------------------------+--------------------------------------------------
Hit the philistines three times over the head with the Elisp reference manual.
                                        - ·······@hal.com (Michael A. Petonic)
From: Robert Monfera
Subject: Re: Making a virtual slots metaclass
Date: 
Message-ID: <389F5410.8B49F150@fisec.com>
I posted a little walk-through of the general process a few months ago:

http://x33.deja.com/[ST_rn=ps]/getdoc.xp?AN=560077206&CONTEXT=949965199.1790443550&hitnum=0

Maybe it helps in your case too, and check out other postings on the
thread too.

Based on how I understand what you want, it would be simpler to create a
generic function and use it - you'd probably access the virtual slots
via accessors, which are also generic functions.  You could automate the
generation of them with the slot definition instance creation or
preferably the class inheritance finalization step (a virtual slot may
be inherited).

To avoid storage allocation for the virtual slot, you can make it
class-allocated.

If you really need to use low-level accessors like SLOT-VALUE,
SLOT-BOUNDP etc. with the virtual slots, you can override them AFAIK.

Robert

Christian Lynbech wrote:
>
> I am trying to create a new metaclass that supports virtual slots, as
> in the following:
>
>         (defclass test ()
>            ((a1 :initform 4)
>             (a2 :allocation :virtual :slot-ref (lambda (o) ...)
>                                      :slot-set! (lambda (o v) ...))))