In article <[EMAIL PROTECTED]>, Pascal Bourguignon <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] writes: > > > I'd like to setf a "place" which is retrieved indirectly with a funcall > > call: > > > > > > (defstruct my > > a b) > > > > (setq myinstance (make-my)) > > > > (setf (my-a myinstance) 33) ; this works > > > > (setq my-get-func 'my-a) > > (setf (funcall my-get-func myinstance) 33) > > ; this doesn't work > > ; "No setf-method known for funcall" > > Write a defsetf-er for funcall! > > > (require 'cl) > > (defmacro with-gensyms (syms &rest body) > `(let ,(mapcar (lambda (s) `(,s ',(gensym (symbol-name s)))) syms) ,@body)) > > (define-setf-method funcall (fun &rest args) > "setf-method for (funcall fun args...)" > (let* ((vfun (eval fun)) This won't work if the code is compiled. SETF is expanded at compile time, but you need to EVAL the variable at run time (and need to do it each time through the loop). > (vexp (get-setf-method `(,vfun ,@args)))) > (message "\n%S\n" vexp) > (when (null vexp) > (error "There is no defsetf for %s in %S" > vfun (cons fun args))) > vexp)) In real Common Lisp, you can only SETF a FUNCALL if the function argument is a literal, since SETF can get the function and its SETF method. E.g. you can do: (setf (funcall #'car) ...) but you can't do: (let ((func #'car)) (setf (funcall func) ...)) -- Barry Margolin, [EMAIL PROTECTED] Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** _______________________________________________ Help-gnu-emacs mailing list Help-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-emacs