I have a simple task: Given a class, I need a function that can add elements to one of the fields of the class. It's easy to do if the function knows the name of the field, but what if the function doesn't know it and we need to pass it as an input parameter to the function. Let's say (defclass test1 () ((fld1 :accessor test1-fld1 :initarg :fld1 :type list)))
(setq o (make-instance 'test1 :fld1 nil)) (defun append-element (o el) (with-slots (fld1) o (setf fld1 (append fld1 (list el)))))
How to modify the append-element function so that it doesn't know about the fld1 and had semantics of (append-element o el field-name) so we can call it like (append-element o 'a 'fld1)?