effective slot definitions
- From: "Alex Mizrahi" <udodenko@xxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 29 Sep 2008 21:34:16 +0300
hi
i don't get how custom effective slot definitions
mechanism is supposed to work by MOP standard.
i was able to find only implementation-specific
examples, and implementation-agnostic version seems
to be daunting.
let's consider a simple case -- we want some fancy
slot definition with additional slot initarg. e.g.:
(defclass fancy-slot-definition (standard-slot-definition)
((fancy :initarg :fancy :accessor fancy-of)))
it's supposed to work like this, in a class definition:
(defclass fancy-object ()
((slot1 :initarg :slot1)
(slot2 :initarg :slot2 :fancy t))
(:metaclass fancy-class))
slot1 should be a standard slot definition,
and slot2 should be a fancy slot definition (slotd).
working with direct slotds is quite straightforward
-- you just specialize direct-slot-definition-class
function for your metaclass, it accepts slot initargs
as parameter, and so you can see if slot is fancy or not.
situation with effective slot definitions looks quite similar
-- you can specialize function
effective-slot-definition-class
and/or compute-effective-slot-definition.
but it only looks so. information that effective-slot-definition-class
is sort of implementation specific (it depends on implementation of
default compute-effective-slot-definition function). in SBCL it
recieves only "standard" initargs, and effectively no information
that we can use to decide if slot is fancy or not.
so we'll have to override compute-effective-slot-definition --
either re-implementing all it's machinery, or somehow re-using
default return value. re-implementing compute-effective-slot-definition
is quite a daunting task -- in SBCL that's about 60 lines of code.
re-using value returned from default c-e-s-d ain't straightforward
-- it seems one needs to call change-class on effective-slot-definition.
so i wonder, was it supposed to be that hard?
as for implementation-specific hacks, they are quite simple.
in Lispworks, effective-slot-definition-class recieves also
original initargs (besides computed ones), so it can decide which class it
is.
in SBCL, one can use sb-pcl::compute-effective-slot-definition-initargs
to reuse most of c-e-s-d machinery, so overriding it goes less daunting.
.
- Follow-Ups:
- Re: effective slot definitions
- From: Pascal Costanza
- Re: effective slot definitions
- Prev by Date: compiling a Lisp source to exe
- Next by Date: Re: RFC 1037 NFILE implementations around?
- Previous by thread: compiling a Lisp source to exe
- Next by thread: Re: effective slot definitions
- Index(es):
Relevant Pages
|