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?
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
slot-value forms, it's the greatest thing because you can use SETQ
instead of SETF.
... because you can use SETQ instead of SETF.
On Wed, 03 Jun 2026 09:21:15 +0530, Madhu wrote:
CanrCOt you use setf for assigning to everything?
Lawrence DrCOOliveiro <ldo@nz.invalid> writes:
CanrCOt you use setf for assigning to everything?
yes and no. setf if a fat macro, setq is preferable to set.
*
it's the greatest thing because you can use SETQ
instead of SETF.
CanrCOt you use setf for assigning to everything?
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?
it's the greatest thing because you can use SETQUh, is this some joke I am missing? Do people really still use SETQ? Do they think it is somehow an advantage? If so, how?
instead of SETF.
yes and no. setf if a fat macro, setq is preferable to set.
Why rCLpreferablerCY? Seems to me you have less to worry about in terms of special cases if you just use setf.
On Thu, 4 Jun 2026 22:42:04 -0000 (UTC), Lawrence DrCOOliveiro wrote:
yes and no. setf if a fat macro, setq is preferable to set.
Why rCLpreferablerCY? 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.
EXCEPT IN SYMBOL-MACROLET where it is defined to
work as SETF, which is the context in which I made the **** comment
... unless you want your programs to have that vintage charm.
On Sun, 7 Jun 2026 16:42:19 -0000 (UTC), tfb wrote:
... unless you want your programs to have that vintage charm.
:)
I've used [setq] because I was used to it from Emacs Lisp ..
Emacs lisp supports setf.
... except in such a case, when it *doesnrCOt* forbid those certain
levels of underlying abstraction from being applicable in that
situation?
Is it still rCLpreferablerCY in that situation?
(Some years ago, I [...] using [...] on Emacs.
[...] It didn't involve Lisp code, though.)
Lawrence D-|Oliveiro <ldo@nz.invalid> wrote:
Emacs lisp supports setf.
It does now, it didn't. I'd certainly use setq if I had to write
elisp again.
On Mon, 8 Jun 2026 07:36:52 -0000 (UTC), tfb wrote:
When did you last do so?
When did you last do so?
I see ... so itrCOs rCLpreferablerCY in the sense that it forbids certain levels of underlying abstraction from being applicable in this
situation?
Lawrence DrCOOliveiro <ldo@nz.invalid> writes:
I see ... so [setq is] rCLpreferablerCY in the sense that it forbids
certain levels of underlying abstraction from being applicable in
this situation?
Sort of like a type annotation, I guess.
Type annotations are supposed to be declarative. You typically write
them once at the point of introduction of the variable, not repeated everywhere you are trying to assign to it.
Lawrence DrCOOliveiro <ldo@nz.invalid> writes:
Type annotations are supposed to be declarative. You typically
write them once at the point of introduction of the variable, not
repeated everywhere you are trying to assign to it.
Lisp isn't Python.
You really think Python invented type annotations?
(Some years ago, I [...] using [...] on Emacs.EfOa
[...] It didn't involve Lisp code, though.)
Lawrence DrCOOliveiro <ldo@nz.invalid> writes:
.
You really think Python invented type annotations?
Python has them in a particular style, other languages use different
styles.
In Haskell you can put them pretty much anywhere.
I had occasion to want to have certain slot-value accesses "redirect" to other slots, so accessing one would seem to affect the other.
On Thu, 04 Jun 2026 17:01:51 -0400, steve g wrote:
Lawrence DrCOOliveiro <ldo@nz.invalid> writes:
CanrCOt you use setf for assigning to everything?
yes and no. setf if a fat macro, setq is preferable to set.
Why rCLpreferablerCY? Seems to me you have less to worry about in terms of special cases if you just use setf.
* Lawrence DrCOOliveiro <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 rCLpreferablerCY? 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
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?
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 70 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 02:02:10 |
| Calls: | 949 |
| Calls today: | 1 |
| Files: | 1,325 |
| Messages: | 281,114 |