Groups | Search | Server Info | Login | Register
Groups > comp.lang.lisp > #60777
| From | Madhu <enometh@meer.net> |
|---|---|
| Newsgroups | comp.lang.lisp |
| Subject | slot-value-using-class to remap "virtual" slots & closer-mop |
| Date | 2026-04-25 20:35 +0530 |
| Organization | Motzarella |
| Message-ID | <m3ldebnkqu.fsf@pison.robolove.meer.net> (permalink) |
I had occasion to want to have certain slot-value accesses "redirect" to
other slots, so accessing one would seem to affect the other.
(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
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.
Back to comp.lang.lisp | Previous | Next — Next in thread | Find similar
slot-value-using-class to remap "virtual" slots & closer-mop Madhu <enometh@meer.net> - 2026-04-25 20:35 +0530
Re: slot-value-using-class to remap "virtual" slots & closer-mop tfb <no_email@invalid.invalid> - 2026-04-25 18:27 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop Madhu <enometh@meer.net> - 2026-05-07 05:22 +0530
Re: slot-value-using-class to remap "virtual" slots & closer-mop Stefan Monnier <monnier@iro.umontreal.ca> - 2026-05-07 15:14 -0400
Re: slot-value-using-class to remap "virtual" slots & closer-mop Madhu <enometh@meer.net> - 2026-05-08 09:48 +0530
csiph-web