I have a list which contains some symbols and values. The goal is to setf the class slot with the accessor, whose symbol is provided by the list :
(defclass my-class ()
((attr :accessor attr)))
(let ((to-call '(attr "some-value"))
(obj (make-instance 'my-class)))
(setf `(,(car to-call) obj) (cadr to-call)))
I have tried via a macro :
(defmacro call-accessor (to-call)
`(setf (,(car to-call) obj) "some-value"))
(let ((to-call '(attr "some-value"))
(obj (make-instance 'my-class)))
(call-accessor to-call))
Which fails too, since to-call
is a symbol and not a list.
eval
does not work sinceto-call
is a lexical variable;- It is not possible to do a
let
over the macro to give it the list; - I have tried with
with-slots
andwith-accessors
but the problem remains the same, because they are macros too. - I have considered macros which declares other macro, and symbol-macrolet too.
How can I setf a slot via an accessor corresponding to a symbol in my list ?
Thank you.