From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: No setf-method known for funcall Date: Thu, 18 Aug 2005 21:59:28 -0400 Organization: Symantec Message-ID: References: <1124368267.221312.44210@g44g2000cwa.googlegroups.com> <871x4r9vbx.fsf@thalassa.informatimago.com> NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1124416998 17521 80.91.229.2 (19 Aug 2005 02:03:18 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 19 Aug 2005 02:03:18 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 19 04:03:12 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1E5wCj-0002oL-Gg for geh-help-gnu-emacs@m.gmane.org; Fri, 19 Aug 2005 04:01:59 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E5wGH-0000DY-HF for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Aug 2005 22:05:37 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail Original-NNTP-Posting-Date: Thu, 18 Aug 2005 20:59:28 -0500 Original-Newsgroups: gnu.emacs.help Mail-Copies-To: nobody User-Agent: MT-NewsWatcher/3.4 (PPC Mac OS X) X-Copies-To: never Original-Lines: 59 Original-NNTP-Posting-Host: 24.128.234.87 Original-X-Trace: sv3-ENdjyh7LvQhFtoRZaildNpzsuBSdR3mfh7OWDOkmuAEGDqhgd44GGbHUhgGLeuF1yI0/mMfKO8UvSdx!05+D9HHVDAffB52kQhjiLIMbyXYnmCmmM80WkHS/pmPBNAGnXfHyAtIG0cHQ0Kf24VyjrXog3QNA!4H5pv14PZOs0bnmt9fsJSDWY1Tp3cmxWRQ== Original-X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Original-Xref: shelby.stanford.edu gnu.emacs.help:133314 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:28840 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:28840 In article <871x4r9vbx.fsf@thalassa.informatimago.com>, Pascal Bourguignon wrote: > 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)) 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, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***