Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.lisp > #60777 > unrolled thread
| Started by | Madhu <enometh@meer.net> |
|---|---|
| First post | 2026-04-25 20:35 +0530 |
| Last post | 2026-06-08 04:06 +0530 |
| Articles | 20 on this page of 26 — 7 participants |
Back to article view | Back to comp.lang.lisp
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
Re: slot-value-using-class to remap "virtual" slots & closer-mop steve g <sgonedes1977@gmail.com> - 2026-06-02 21:50 -0400
Re: slot-value-using-class to remap "virtual" slots & closer-mop Madhu <enometh@meer.net> - 2026-06-03 09:21 +0530
Re: slot-value-using-class to remap "virtual" slots & closer-mop steve g <sgonedes1977@gmail.com> - 2026-06-03 22:48 -0400
Re: slot-value-using-class to remap "virtual" slots & closer-mop Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-04 03:22 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop steve g <sgonedes1977@gmail.com> - 2026-06-04 17:01 -0400
Re: slot-value-using-class to remap "virtual" slots & closer-mop Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-04 22:42 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop Madhu <enometh@meer.net> - 2026-06-08 04:13 +0530
Re: slot-value-using-class to remap "virtual" slots & closer-mop Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-07 23:22 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop tfb <no_email@invalid.invalid> - 2026-06-08 07:52 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop tfb <no_email@invalid.invalid> - 2026-06-07 16:42 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-07 23:24 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop Nuno Silva <nunojsilva@invalid.invalid> - 2026-06-08 00:57 +0100
Re: slot-value-using-class to remap "virtual" slots & closer-mop Stefan Monnier <monnier@iro.umontreal.ca> - 2026-06-08 09:25 -0400
Re: slot-value-using-class to remap "virtual" slots & closer-mop tfb <no_email@invalid.invalid> - 2026-06-07 16:31 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop Paul Rubin <no.email@nospam.invalid> - 2026-06-07 12:31 -0700
Re: slot-value-using-class to remap "virtual" slots & closer-mop Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-08 02:27 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop tfb <no_email@invalid.invalid> - 2026-06-08 07:36 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-09 00:30 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop steve g <sgonedes1977@gmail.com> - 2026-06-09 00:25 -0400
Re: slot-value-using-class to remap "virtual" slots & closer-mop tfb <no_email@invalid.invalid> - 2026-06-09 05:49 +0000
Re: slot-value-using-class to remap "virtual" slots & closer-mop Madhu <enometh@meer.net> - 2026-06-08 04:06 +0530
Page 1 of 2 [1] 2 Next page →
| From | Madhu <enometh@meer.net> |
|---|---|
| Date | 2026-04-25 20:35 +0530 |
| Subject | slot-value-using-class to remap "virtual" slots & closer-mop |
| Message-ID | <m3ldebnkqu.fsf@pison.robolove.meer.net> |
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.
[toc] | [next] | [standalone]
| From | tfb <no_email@invalid.invalid> |
|---|---|
| Date | 2026-04-25 18:27 +0000 |
| Message-ID | <10sj12c$11lo5$1@dont-email.me> |
| In reply to | #60777 |
Madhu <enometh@meer.net> wrote: > > > any pitfalls comments or alternative implementations You need a slot-boundp-using-class method at least. And to build a package so your code isn't full of package-qualified names, though I realise that's now a list cause. Indeed I am working on an implementation which will require all names to be of the form impl:thing-nobody-understands:version:package:actual-symbol-name. I feel this will be wildly successful. -- www.tfeb.org/computer/
[toc] | [prev] | [next] | [standalone]
| From | Madhu <enometh@meer.net> |
|---|---|
| Date | 2026-05-07 05:22 +0530 |
| Message-ID | <m37bpg14fm.fsf@pison.robolove.meer.net> |
| In reply to | #60777 |
* 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.
[toc] | [prev] | [next] | [standalone]
| From | Stefan Monnier <monnier@iro.umontreal.ca> |
|---|---|
| Date | 2026-05-07 15:14 -0400 |
| Message-ID | <jwvcxz7doj6.fsf-monnier+comp.lang.lisp@gnu.org> |
| In reply to | #60787 |
> 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? === Stefan
[toc] | [prev] | [next] | [standalone]
| From | Madhu <enometh@meer.net> |
|---|---|
| Date | 2026-05-08 09:48 +0530 |
| Message-ID | <m3wlxezg7l.fsf@pison.robolove.meer.net> |
| In reply to | #60788 |
* Stefan Monnier <jwvcxz7doj6.fsf-monnier+comp.lang.lisp@gnu.org> :
Wrote on Thu, 07 May 2026 15:14:24 -0400:
>> 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?
Yes, I was able to replace all that slot-value-using-class machinery
with slot-missing.
(defclass foo ()
((slot-1 :initform 10 :initarg :slot-1)))
(defmethod slot-missing ((class standard-class) (obj foo) slot operation
&optional new-value)
(let ((slot-name
(etypecase slot
(symbol slot)
(ccl:standard-effective-slot-definition
(ccl:slot-definition-name slot)))))
(case slot-name
(slot-2
(ecase operation
(setf (setf (slot-value obj 'slot-1) new-value))
(slot-boundp (slot-boundp obj 'slot-1))
(slot-makunbound (slot-makunbound obj 'slot-1))
(slot-value (slot-value obj 'slot-1))))
(slot-3
(ecase operation
(setf (setf (slot-value obj 'slot-1) new-value))
(slot-boundp (slot-boundp obj 'slot-1))
(slot-makunbound (slot-makunbound obj 'slot-1))
(slot-value (slot-value obj 'slot-1))))
(otherwise (call-next-method)))))
This redirects or "forwards" slot-value operations on slot-3 and slot-2
to slot-1.
(setq $f (make-instance 'foo))
(slot-value $f 'slot-1) ; 10
(slot-value $f 'slot-2) ;10
(setf (slot-value $f 'slot-3) 20) ;20
I thought the only drawback is when slot-missing is signalled with the
"setf" operation, that the spec specifies the setf operation doesn't
return a value, but I think I misread it since it does
[toc] | [prev] | [next] | [standalone]
| From | steve g <sgonedes1977@gmail.com> |
|---|---|
| Date | 2026-06-02 21:50 -0400 |
| Message-ID | <87eciocrz9.fsf@gmail.com> |
| In reply to | #60789 |
Madhu <enometh@meer.net> writes: > > Yes, I was able to replace all that slot-value-using-class machinery > with slot-missing. > > (defclass foo () > ((slot-1 :initform 10 :initarg :slot-1))) > > (defmethod slot-missing ((class standard-class) (obj foo) slot operation > &optional new-value) > (let ((slot-name > (etypecase slot > (symbol slot) > (ccl:standard-effective-slot-definition > (ccl:slot-definition-name slot))))) > (case slot-name > (slot-2 > (ecase operation > (setf (setf (slot-value obj 'slot-1) new-value)) > (slot-boundp (slot-boundp obj 'slot-1)) > (slot-makunbound (slot-makunbound obj 'slot-1)) > (slot-value (slot-value obj 'slot-1)))) > (slot-3 > (ecase operation > (setf (setf (slot-value obj 'slot-1) new-value)) > (slot-boundp (slot-boundp obj 'slot-1)) > (slot-makunbound (slot-makunbound obj 'slot-1)) > (slot-value (slot-value obj 'slot-1)))) > (otherwise (call-next-method))))) > > > This redirects or "forwards" slot-value operations on slot-3 and slot-2 > to slot-1. have you tried with-slots macro? https://www.lispworks.com/documentation/HyperSpec/Body/m_w_slts.htm
[toc] | [prev] | [next] | [standalone]
| From | Madhu <enometh@meer.net> |
|---|---|
| Date | 2026-06-03 09:21 +0530 |
| Message-ID | <m3o6hscmdo.fsf@pison.robolove.meer.net> |
| In reply to | #60799 |
* steve g <87eciocrz9.fsf@gmail.com> : Wrote on Tue, 02 Jun 2026 21:50:18 -0400: > > have you tried with-slots macro? > > https://www.lispworks.com/documentation/HyperSpec/Body/m_w_slts.htm yes, haven't checked but it's a "symbol macro" which expands to slot-value forms, it's the greatest thing because you can use SETQ instead of SETF.
[toc] | [prev] | [next] | [standalone]
| From | steve g <sgonedes1977@gmail.com> |
|---|---|
| Date | 2026-06-03 22:48 -0400 |
| Message-ID | <87cxy7vx5q.fsf@gmail.com> |
| In reply to | #60801 |
Madhu <enometh@meer.net> writes: > slot-value forms, it's the greatest thing because you can use SETQ > instead of SETF. agreed!
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D’Oliveiro <ldo@nz.invalid> |
|---|---|
| Date | 2026-06-04 03:22 +0000 |
| Message-ID | <10vqr13$4jdd$1@dont-email.me> |
| In reply to | #60801 |
On Wed, 03 Jun 2026 09:21:15 +0530, Madhu wrote: > ... because you can use SETQ instead of SETF. Can’t you use setf for assigning to everything?
[toc] | [prev] | [next] | [standalone]
| From | steve g <sgonedes1977@gmail.com> |
|---|---|
| Date | 2026-06-04 17:01 -0400 |
| Message-ID | <87se72xbnk.fsf@gmail.com> |
| In reply to | #60803 |
Lawrence D’Oliveiro <ldo@nz.invalid> writes:
> On Wed, 03 Jun 2026 09:21:15 +0530, Madhu wrote:
>
< > ... because you can use SETQ instead of SETF.
>
> Can’t you use setf for assigning to everything?
yes and no. setf if a fat macro, setq is preferable to set.
check https://www.lispworks.com/documentation/HyperSpec/Body/f_set.htm
setf = set field
setq = set quote
set = set
; SLIME 2.26.1
CL-USER>
; No value
CL-USER>
; No value
CL-USER> (defvar xyz)
XYZ
CL-USER> (set 'xyz 123)
123
CL-USER> xyz
123
CL-USER> (setq xyz (make-array 10 :element-type 'symbol :initial-element nil))
#(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)
CL-USER> xyz
#(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)
CL-USER> (setf (aref 0 xyz 3) 'three)
; Evaluation aborted on #<TYPE-ERROR expected-type: ARRAY datum: 0>.
CL-USER> (setf (aref xyz 3) 'three)
THREE
CL-USER> (loop for i downfrom (1- (length xyz)) to 0
do (setf (aref xyz i) t))
NIL
CL-USER> xyz
#(T T T T T T T T T T)
CL-USER> (setq (aref xyz 2) nil)
; Evaluation aborted on #<TYPE-ERROR expected-type: SYMBOL datum: (AREF XYZ 2)>.
CL-USER>
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D’Oliveiro <ldo@nz.invalid> |
|---|---|
| Date | 2026-06-04 22:42 +0000 |
| Message-ID | <10vsuvs$nejc$4@dont-email.me> |
| In reply to | #60804 |
On Thu, 04 Jun 2026 17:01:51 -0400, steve g wrote: > Lawrence D’Oliveiro <ldo@nz.invalid> writes: > >> Can’t you use setf for assigning to everything? > > yes and no. setf if a fat macro, setq is preferable to set. Why “preferable”? Seems to me you have less to worry about in terms of special cases if you just use setf.
[toc] | [prev] | [next] | [standalone]
| From | Madhu <enometh@meer.net> |
|---|---|
| Date | 2026-06-08 04:13 +0530 |
| Message-ID | <m3pl220y50.fsf@pison.robolove.meer.net> |
| In reply to | #60805 |
* Lawrence D’Oliveiro <10vsuvs$nejc$4@dont-email.me> : Wrote on Thu, 4 Jun 2026 22:42:04 -0000 (UTC): >> yes and no. setf if a fat macro, setq is preferable to set. > > Why “preferable”? Seems to me you have less to worry about in terms of > special cases if you just use setf. Here we go again. SETQ modified bindings. variable bindings. SETF is a generalized mechanism to modify "places" (which includes variable bindings) using SETQ signals that there is nothing complicated going on under the surface syntax. EXCEPT IN SYMBOL-MACROLET where it is defined to work as SETF, which is the context in which I made the **** comment
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D’Oliveiro <ldo@nz.invalid> |
|---|---|
| Date | 2026-06-07 23:22 +0000 |
| Message-ID | <1104ueq$2rlf4$4@dont-email.me> |
| In reply to | #60811 |
On Mon, 08 Jun 2026 04:13:55 +0530, Madhu wrote: > On Thu, 4 Jun 2026 22:42:04 -0000 (UTC), Lawrence D’Oliveiro wrote: >> >>> yes and no. setf if a fat macro, setq is preferable to set. >> >> Why “preferable”? Seems to me you have less to worry about in terms >> of special cases if you just use setf. > > using SETQ signals that there is nothing complicated going on under > the surface syntax. I see ... so it’s “preferable” in the sense that it forbids certain levels of underlying abstraction from being applicable in this situation? > EXCEPT IN SYMBOL-MACROLET where it is defined to > work as SETF, which is the context in which I made the **** comment ... except in such a case, when it *doesn’t* forbid those certain levels of underlying abstraction from being applicable in that situation? Is it still “preferable” in that situation?
[toc] | [prev] | [next] | [standalone]
| From | tfb <no_email@invalid.invalid> |
|---|---|
| Date | 2026-06-08 07:52 +0000 |
| Message-ID | <1105sbh$32ieu$1@dont-email.me> |
| In reply to | #60812 |
Lawrence D´Oliveiro <ldo@nz.invalid> wrote: > > ... except in such a case, when it *doesn’t* forbid those certain > levels of underlying abstraction from being applicable in that > situation? Or in any other case where the thing you think is a variable is a binding established by some form, which may, behind the scenes, use a symbol macro instead, or *sometimes* use a symbol macro. It probably is the case that LET itself is not allowed to do that (so variables actually exist). As an example of this my SITH-SHORTHANDS macro will cause its bindings to be variables if you've used the read-once option, otherwise they'll be symbol macros. Or may be it is more complicated than that: I forget. I mean, on the assumption that LET, LAMBDA etc are not allowed to use symbol macros (I think they are probably not, but I'm not sure if the spec really says that) then the *only* place SETQ would be 'preferable' is where the variable is bound by one of those forms. > > Is it still “preferable” in that situation? > It's never preferable... -- www.tfeb.org/computer/
[toc] | [prev] | [next] | [standalone]
| From | tfb <no_email@invalid.invalid> |
|---|---|
| Date | 2026-06-07 16:42 +0000 |
| Message-ID | <110471b$2l3uf$1@dont-email.me> |
| In reply to | #60803 |
Lawrence D´Oliveiro <ldo@nz.invalid> wrote: > Can’t you use setf for assigning to everything? > Yes. It has no runtime cost, the whole 'fat macro' someone mentioned is confused. In particular (setf (symbol-value x) y) and(set x y) are entirely the same thing. You never need to use SET or SETQ (or RPLACA, or ...) unless you want your programs to have that vintage charm. Things that arrived (or were heavily modified) in CL don't even have update functions: there's no ASET for instance. -- www.tfeb.org/computer/
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D’Oliveiro <ldo@nz.invalid> |
|---|---|
| Date | 2026-06-07 23:24 +0000 |
| Message-ID | <1104uio$2rlf4$5@dont-email.me> |
| In reply to | #60808 |
On Sun, 7 Jun 2026 16:42:19 -0000 (UTC), tfb wrote: > ... unless you want your programs to have that vintage charm. :)
[toc] | [prev] | [next] | [standalone]
| From | Nuno Silva <nunojsilva@invalid.invalid> |
|---|---|
| Date | 2026-06-08 00:57 +0100 |
| Message-ID | <11050hn$2rflv$2@dont-email.me> |
| In reply to | #60813 |
On 2026-06-08, Lawrence D’Oliveiro wrote: > On Sun, 7 Jun 2026 16:42:19 -0000 (UTC), tfb wrote: > >> ... unless you want your programs to have that vintage charm. > > :) That's what terminals are for. You may be limited by lack of UCS coverage, but you can perhaps get a "vintage charm" out of the coding experience :-) (Some years ago, I did write one MSc thesis partially using a terminal, LaTeX on Emacs. It tended to be an ergonomic setup for me. It didn't involve Lisp code, though.) -- Nuno Silva
[toc] | [prev] | [next] | [standalone]
| From | Stefan Monnier <monnier@iro.umontreal.ca> |
|---|---|
| Date | 2026-06-08 09:25 -0400 |
| Message-ID | <jwvldcpnp1v.fsf-monnier+comp.lang.lisp@gnu.org> |
| In reply to | #60814 |
> (Some years ago, I [...] using [...] on Emacs. > [...] It didn't involve Lisp code, though.) 🙃 === Stefan
[toc] | [prev] | [next] | [standalone]
| From | tfb <no_email@invalid.invalid> |
|---|---|
| Date | 2026-06-07 16:31 +0000 |
| Message-ID | <11046ce$2ktnj$1@dont-email.me> |
| In reply to | #60801 |
Madhu <enometh@meer.net> wrote: > > * > it's the greatest thing because you can use SETQ > instead of SETF. > Uh, is this some joke I am missing? Do people really still use SETQ? Do they think it is somehow an advantage? If so, how? -- www.tfeb.org/computer/
[toc] | [prev] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2026-06-07 12:31 -0700 |
| Message-ID | <877boa9mgg.fsf@nightsong.com> |
| In reply to | #60807 |
tfb <no_email@invalid.invalid> writes: > Uh, is this some joke I am missing? Do people really still use SETQ? Do > they think it is somehow an advantage? If so, how? I've used it because I was used to it from Emacs Lisp and I had it in a special purpose non-CL Lisp that I wrote a while back. Maybe both count as "vintage charm". Yeah SETF in CL is more idiomatic.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.lisp
csiph-web