From: Pascal Bourguignon <spam@mouse-potato.com>
Subject: Re: No setf-method known for funcall
Date: Fri, 19 Aug 2005 05:47:07 +0200 [thread overview]
Message-ID: <87y86y7flw.fsf@thalassa.informatimago.com> (raw)
In-Reply-To: barmar-317B0B.21592818082005@comcast.dca.giganews.com
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------
prev parent reply other threads:[~2005-08-19 3:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-18 12:31 No setf-method known for funcall kcin
2005-08-18 14:24 ` Pascal Bourguignon
2005-08-19 1:59 ` Barry Margolin
2005-08-19 3:47 ` Pascal Bourguignon [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y86y7flw.fsf@thalassa.informatimago.com \
--to=spam@mouse-potato.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).