I'd like to setf
different fields of a struct depending on a certain variable. I decided to use the following approach:
Generate a string with the field's accessor name:
(setq my-string (format nil "STRUCT-ESTADISTICAS-NUM-~S" x))
and then use intern with funcall:
(funcall (intern my-string) *estadisticas*)
This call returns the correct value of the struct's field, but if I try setf
to modify this value it complains saying:
(setf (funcall(intern my-string) *estadisticas*) 0)
Error: `(SETF FUNCALL)' is not fbound
I can understand why it doesn't work, but I can't find a way to modify the struct's fields. Any idea? Thank you.
You want to call a writer function of the struct via its name, and the name of the writer is the list
(setf accessor-name)
; soEdit:
Not seeing the rest of your code, it's hard to fathom what went wrong. On SBCL this works for me:
The above evaluates to
as expected.