Turning variables into function names with setf
Posted: Sun Mar 28, 2010 11:10 pm
I seem to be having conceptual difficulty turning a variable into a function. A simple example is looping through the accessors in a class-instance.
(defclass tst ()
((id :accessor id :initarg :id :initform 0)
(name :accessor name :initarg :name :initform "test-me")))
Then if I have a list of data, I'd like to be able to just loop through the list of accessors. But if I try something like (assume a function get-data exists:
(defun test-commit (item)
(loop for fn in '(id name)
do (setf (funcall fn item) (get-data fn))))
I get a message that (setf funcall) is an undefined function and reserved by ANSI CL
Suggestions or pointers would be appreciated.
Sabra
(defclass tst ()
((id :accessor id :initarg :id :initform 0)
(name :accessor name :initarg :name :initform "test-me")))
Then if I have a list of data, I'd like to be able to just loop through the list of accessors. But if I try something like (assume a function get-data exists:
(defun test-commit (item)
(loop for fn in '(id name)
do (setf (funcall fn item) (get-data fn))))
I get a message that (setf funcall) is an undefined function and reserved by ANSI CL
Suggestions or pointers would be appreciated.
Sabra