I am stumped on effective vs direct slot definition.
I am trying to allow some slots of instances under a metaclass have
standard slot definitions, while other slots get a slot definition
custom to the metaclass. I am starting to think that is not how it is
done. :)
here is a sample (and FWIW, I am using ACL 5.0):
(defclass DirectXSD (standard-direct-slot-definition)
(
(xxarg :initform nil
:initarg :xxArg
:accessor xxarg)
))
(defclass EffectiveXSD (standard-effective-slot-definition)
(
(xxarg :initform nil
:initarg :xxArg
:accessor xxarg)
))
(defclass XXClass (standard-class)
())
(defmethod direct-slot-definition-class ((mClass XXClass) &rest iargs
&key name xxArg)
(declare (ignore-if-unused name xxArg))
(if xxArg
(progn (print "Bingo Direct")
(find-class 'DirectXSD))
(call-next-method))
)
(defmethod effective-slot-definition-class ((mClass XXClass) &rest iargs
&key name xxArg)
(declare (ignore-if-unused name xxArg))
(if xxArg
(progn (print "Bingo Effective")
(find-class 'EffectiveXSD))
(call-next-method)))
(defclass XX ()
((yy)
(xx :xxarg t))
(:metaclass xxclass))
What I want is for slot 'yy to be standard and slot 'xx to be
'effectiveXSD.
Well, I manage to generate 'xx as 'DirectXSD but not 'EffectiveXSD
(confirmed by trace output as well as inspecting an instance) and I can
see that is because, duh, the :xxarg key is supplied to
'direct-slot-definition-class but not 'effective-....
To tell you the truth, i really don't get it (and I have consulted AMOP,
but it's a little terse). the two functions seem to be asking me to make
the same decision twice. I could see if 'effective-slot-definition were
passed the direct-slot-definition identified in the first call, but it's
not. It gets initargs again--but not all of them!
I thought of always returning 'EffectiveXSD, but that just makes all my
slot definitions EffectiveXSD.
I really don't get it. Help! :)
kenny
From: Fernando Mato Mira
Subject: Re: Stump on MOP in re Slot definition
Date:
Message-ID: <37D63135.29255CB5@iname.com>
Kenny Tilton wrote:
> I am stumped on effective vs direct slot definition.
>
> Well, I manage to generate 'xx as 'DirectXSD but not 'EffectiveXSD
> (confirmed by trace output as well as inspecting an instance) and I can
> see that is because, duh, the :xxarg key is supplied to
> 'direct-slot-definition-class but not 'effective-....
You need to specialize COMPUTE-EFFECTIVE-SLOT-DEFINITION.
It doesn't know it has to extract xxarg from the dslotd and pass it on to
EFFECTIVE-SLOT-DEFINITION-CLASS, as well as MAKE-INSTANCE.
From: Kenny Tilton
Subject: Re: Stump on MOP in re Slot definition
Date:
Message-ID: <37D6BBEA.7BA7798@liii.com>
>
> You need to specialize COMPUTE-EFFECTIVE-SLOT-DEFINITION.
> It doesn't know it has to extract xxarg from the dslotd and pass it on to
> EFFECTIVE-SLOT-DEFINITION-CLASS, as well as MAKE-INSTANCE.
Thx, Fernando. C-E-S-D it is for me.
I think a light just went on, but let me check:
If we have nothing fancy to do with effective slotd's (ESDs),
specializing just EFFECTIVE-SLOT-DEFINITION-CLASS is a /convenience/. If
we want to get fancy and generate different ESDs for different (defclass
...) expressions, we use the greater control and fuller information
available in COMPUTE-EFFECTIVE-SLOT-DEFINITION.
The thing that had me going in circles was thinking E-S-D-C was the
one-and-only entry point for tailoring ESDs, but it is really just a
convenience for those who want the same ESD for all slots.
Close?? :)
kenny
clinisys
From: Fernando Mato Mira
Subject: Re: Stump on MOP in re Slot definition
Date:
Message-ID: <37D77E3D.4092E352@iname.com>
Kenny Tilton wrote:
> If we have nothing fancy to do with effective slotd's (ESDs),
> specializing just EFFECTIVE-SLOT-DEFINITION-CLASS is a /convenience/. If
> we want to get fancy and generate different ESDs for different (defclass
> ...) expressions, we use the greater control and fuller information
> available in COMPUTE-EFFECTIVE-SLOT-DEFINITION.
I would say COMPUTE-EFFECTIVE-SLOT-DEFINITION is missing a subprotocol:
(defmethod compute-effective-slot-definition ((class standard-class)
direct-slots)
(let ((args (COMBINE-SLOTS class direct-slots))
(apply #'make-instance (apply #'effective-slot-definition-class class
args) args)))
where
(defgeneric combine-slots(class direct-slots))
(defmethod combine-slots ((class standard-class) direct-slots)
(let ((initer (find-if-not #'null direct-slots :key
#'slot-definition-initfunction)))
(list :name (slot-definition-name (car direct-slots))
:initform (if initer (slot-definition-initform initer) nil)
:initfunction (if initer (slot-definition-initfunction initer) nil)
:initargs (remove-duplicates (mapappend #'slot-definition-initargs
direct-slots))
:readers (remove-duplicates (mapappend #'slot-definition-readers
direct-slots))
:writers (remove-duplicates (mapappend #'slot-definition-writers
direct-slots))
:allocation (slot-definition-allocation (car direct-slots))
)))
Then you could have done (if xxArg just overrides, for example):
(defmethod combine-slots ((mClass XXClass) direct-slots)
(let ((stdargs (call-next-method))
((arg (find-if-not #'null direct-slots :key #'xxArg))) ; default
#'xxArg method should return nil
(if arg
(cons :xxArg (cons arg stdargs))
stdargs)))
Instead of having to mess up with COMPUTE-EFFECTIVE-SLOT-DEFINITION.
BTW, note that to provide non-`virtual' [C++ terminology] semantics (maybe
providing Eiffel-like renaming facilities) you have to specialize COMPUTE-SLOTS
(duh).
From: Kenny Tilton
Subject: Re: Stump on MOP in re Slot definition
Date:
Message-ID: <37D7A8EA.31849EA3@liii.com>
>
> I would say COMPUTE-EFFECTIVE-SLOT-DEFINITION is missing a subprotocol:
>
> (defmethod compute-effective-slot-definition ((class standard-class)
> direct-slots)
> (let ((args (COMBINE-SLOTS class direct-slots))
> (apply #'make-instance (apply #'effective-slot-definition-class class
> args) args)))
>
This is scary...here is the solution I settled on yesterday (look
familiar? <g>):
(defmethod compute-effective-slot-definition ((mClass DataflowClass)
slot dsds)
(declare (ignore-if-unused slot))
(bIf (dfd (find-if #'(lambda (dsd) (typep dsd 'DataflowDSD)) dsds)) ;;
binding If
(apply #'make-instance (case (semaphor dfd)
(:ephemeral 'DFEphemeralESD)
(:drifter 'DFDrifterESD)
(:delta 'DFDeltaESD)
(otherwise 'DataflowESD))
(clos::compute-effective-slot-definition-initargs mClass
dsds)) ;; <== your 'COMBINE-SLOTS!!
(call-next-method))) ;; punt to standard ESD
I guess someone at Franz agreed with you and added 'COMPUTE-esd-INITARGS
to ACL's CLOS.
kenny
CliniSys
From: Fernando Mato Mira
Subject: Re: Stump on MOP in re Slot definition
Date:
Message-ID: <37D8C496.1072A1C7@iname.com>
Kenny Tilton wrote:
> (clos::compute-effective-slot-definition-initargs mClass
> dsds)) ;; <== your 'COMBINE-SLOTS!!
Actually, I liked this name but I didn't call it like that because someone might
think this only combines the results of SLOT-DEFINITION-INITARGS [not that
COMBINE-SLOTS is a great one].
Your esds make me curious..
From: Kenny Tilton
Subject: Re: Stump on MOP in re Slot definition
Date:
Message-ID: <37D8ECE4.3F8F4928@liii.com>
>
> Your esds make me curious..
Well, I hope to write it all up in time for the upcoming LUGM
conference. I missed the paper deadline (by a mile) but I'll bring some
copies along for anyone interested. I'll e-mail you a PDF if/when I get
it together.
Come to think of it, I stumbled across a note I had sent to the referee
describing the work and it struck me as not a bad start. I'll dig it up
and mail it to you.
In brief, over the past few years I have without really intending to
engineered a pretty clean little dataflow mechanism on top of Lisp. All
sorts of variations, as those ESDs suggest, and I am sure the potential
for more such semantic twists is extensive.
I wouldn't think of building an application the procedural way anymore.
Sometimes I unconsciously backslide into that mode, but soon enough I
get a creepy deja vu thing and realize I have strayed. :)
An application is like a spreadsheet now. Pretty transparent, too, and
with a metaclass implementation it could be even more so.
Thx again for the assist. I'll go find that note now.
kenny
clinisys
From: Fernando Mato Mira
Subject: Re: Stump on MOP in re Slot definition
Date:
Message-ID: <37D91C78.8A6751C5@iname.com>
Kenny Tilton wrote:
> In brief, over the past few years I have without really intending to
> engineered a pretty clean little dataflow mechanism on top of Lisp. All
OK. Which university wants to give me a piece of paper that says "Ph.D." and
wants to become the home of ECLOS?
The thing should really be out there being used..