any pitfalls comments or alternative implementations
I had occasion to want to have certain slot-value accesses "redirect" to other slots, so accessing one would seem to affect the other.;; should be 10
(defclass foo ()
((slot-1 :initform 10))
(#+lispworks :optimize-slot-access #+lispworks nil))
this is the behaviour which is required
(setq $f (make-instance 'foo))
(slot-value $f 'slot-1) ; 30
(setf (slot-value $f 'slot-3) 20)
(slot-value $f 'slot-1) ; => 30--- Synchronet 3.21f-Linux NewsLink 1.2
here is the expanded boilerplate which maps 'slot-2' and 'slot-3' to
'slot-1'
(defmethod c2mop:slot-value-using-class
((class standard-class) (obj foo) slot)
(let ((slot-name
(etypecase slot
(symbol slot)
(c2mop:standard-effective-slot-definition
(c2mop:slot-definition-name slot)))))
(case slot-name
(slot-2 (slot-value obj 'slot-1))
(slot-3 (slot-value obj 'slot-2))
(otherwise (call-next-method)))))
(defmethod (setf c2mop:slot-value-using-class)
(value (class standard-class) (obj foo) slot)
(let ((slot-name
(etypecase slot
(symbol slot)
(c2mop:standard-effective-slot-definition
(c2mop:slot-definition-name slot)))))
(case slot-name
(slot-2 (setf (slot-value obj 'slot-1) value))
(slot-3 (setf (slot-value obj 'slot-2) value))
(otherwise (call-next-method)))))
any pitfalls comments or alternative implementations
i'm using standard-class but maybe i should be using
c2mop:standard-class (and c2mop:defmethod) instead, i couldn't spot any documentation on closer-mop on how it is to be used, the objects are
slightly different, and i'm not able to assess if there is an impact
across implementaions.
Apparently this only works on lispworks. all other lisps I tried fail at
this step i.e. accessing the "virtual slot" slot-3, saying the slot does
not exist.
Apparently this only works on lispworks. all other lisps I tried fail at
this step i.e. accessing the "virtual slot" slot-3, saying the slot does
not exist.
I'm not sure I understand the details of what you're looking for (I get
the impression that your original example had typos that made it too confusing for my little brain), but maybe you can use the
`slot-missing` method?
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 03:07:11 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
10 files (20,373K bytes) |
| Messages: | 264,422 |