Is there an equivalent in Scheme of Common Lisp's defsetf
?
views:
69answers:
2
A:
I don't think there is. I think defsetf
allows you to do things in Lisp like (setf (car x) 5)
i.e. use what appears to be the result of a function as an l-value. But in Scheme, they have to define separate mutating functions, like set-car!
and set-cdr!
, to accomplish the same task; the above example would be (set-car! x 5)
.
newacct
2009-08-11 02:28:05
You need these functions in CL too (for example, `rplaca`) -- `setf` is just syntax that expands to them.
Eli Barzilay
2009-08-12 18:08:05
+2
A:
I'm pretty sure that there isn't an equivalent in standard (RnRS) Scheme, but SRFI 17, which is supported by some Scheme implementations, allows you to define setters for generalized places.
Pillsy
2009-08-11 02:31:55
Note that srfi-17 uses the runtime value of the accessor, not the form itself. It's a minor difference but it can be important (usually it means that it's a little slower, and a little more flexible).
Eli Barzilay
2009-08-12 18:09:18