[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: No setf-method known for funcall
From: |
Pascal Bourguignon |
Subject: |
Re: No setf-method known for funcall |
Date: |
Thu, 18 Aug 2005 16:24:34 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
kcin@mytrashmail.com 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))
(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))
(progn
(setf x (cons :a :b))
(setf f (function cdr))
(setf (funcall f x) 1)
(insert (format "--> %S\n" x))
(dolist (f (list (function car) (function cdr)))
(setf (funcall f x) 2))
(insert (format "--> %S\n" x)))
--> (:a . 1)
--> (2 . 2)
--
"By filing this bug report you have challenged the honor of my
family. Prepare to die!"