Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.lisp > #60787
| From | Madhu <enometh@meer.net> |
|---|---|
| Newsgroups | comp.lang.lisp |
| Subject | Re: slot-value-using-class to remap "virtual" slots & closer-mop |
| Date | 2026-05-07 05:22 +0530 |
| Organization | Motzarella |
| Message-ID | <m37bpg14fm.fsf@pison.robolove.meer.net> (permalink) |
| References | <m3ldebnkqu.fsf@pison.robolove.meer.net> |
* In <m3ldebnkqu.fsf@pison.robolove.meer.net> : I Wrote on Sat, 25 Apr 2026 20:35:29 +0530: > 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 ;; should be 10 > (setf (slot-value $f 'slot-3) 20) 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. since is not found in (class-slots (find-class 'foo)) and the suggested definition of slot-value involves finding the slot in class-slots before passing it to s-v-u-c but the goal was to have slot-3 be a "virtual" slot. So I'm back to square 1 in trying to implement these "virtual slot redirects" > (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 — Previous in thread | 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