help-gnu-emacs
[Top][All Lists]
Advanced

[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: Fri, 19 Aug 2005 05:47:07 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Barry Margolin <barmar@alum.mit.edu> writes:
> In article <871x4r9vbx.fsf@thalassa.informatimago.com>,
>  Pascal Bourguignon <spam@mouse-potato.com> wrote:
>> Write a defsetf-er for funcall!
>[...]
>> (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).

Indeed.

One problem to implement a run-time setf funcall, is that setf-ers are
defined from the name of the function:

(defun example (cons) (car cons))
(defun set-example (cons value) 
       (format *trace-output* "set-example")
       (setf (car cons) value))

(setf (symbol-function 'test) (symbol-function 'example))

(setf (symbol-function test) (symbol-function example))
(defun set-test (cons value)
       (format *trace-output* "set-test")
       (setf (car cons) value))
(defsetf test set-test)

(setf x (cons 0 0))

[44]> (setf (example x) 1)
set-example
1
[45]> (setf (test    x) 2)

set-test
2

But:
(setf fun (function test))
(setf (funcall fun x) 1)

could not know whether to use set-example or set-test, 
for (and (eq fun (function example)) (eq fun (function test)))


To make (setf (funcall ...) ...) work, we'd have to associate the
setters to the function objects instead of the function names (the
symbols).

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d? s++:++ a+ C+++ UL++++ P--- L+++ E+++ W++ N+++ o-- K- w--- 
O- M++ V PS PE++ Y++ PGP t+ 5+ X++ R !tv b+++ DI++++ D++ 
G e+++ h+ r-- z? 
------END GEEK CODE BLOCK------


reply via email to

[Prev in Thread] Current Thread [Next in Thread]