[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problems with setf and structures
Using CLOS, there is a better solution to your problem. Using CLOS and
taking advantage of one of the cleanup committee's proposals to cleanup
setf there is an even better solution.
Solution 1 - Using CLOS.
(defsetf foo-a set-foo-a)
(defsetf foo-b set-foo-b)
.
.
(defun test ()
(let (x)
(add-named-class
:name foo
:superclasses ()
:slot-specifications '((a :reader foo-a
:writer set-foo-a)
(b :reader foo-b
:writer set-foo-b)
.
.))
(setq x (make-instance 'foo))
(setf (foo-a x) 1)))
Solution 2 - Using CLOS and cleanup up setf
The basic difference is that you don't have to do the defsetfs. The
reason is that setf is defined to expand into a well-know function when
there hasn't been an explicit defsetf done.
(defun test ()
(let (x)
(add-named-class
:name foo
:superclasses ()
:slot-specifications '((a :accessor foo-a)
(b :accessor foo-b)
.
.))
(setq x (make-instance 'foo))
(setf (foo-a x) 1)))
-------