views:

69

answers:

2

Is there an equivalent in Scheme of Common Lisp's defsetf?

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
You need these functions in CL too (for example, `rplaca`) -- `setf` is just syntax that expands to them.
Eli Barzilay
+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
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