From: Rand Sobriquet
Subject: Funcalling writer methods
Date: 
Message-ID: <1e249696.0311152111.3b582a80@posting.google.com>
; I have a question about funcalling.

; Let's say that I have this:

(defclass test ()
  ((test-slot :accessor test-slot :initform 'empty)))

(defun read-slot (fn object)
  (format t "~A" (funcall fn object)))

(read-slot #'test-slot (make-instance 'test))

; All this works as expected. But when I define:

(defun set-slot (fn object)
  (setf (funcall fn object) 'filled))


; I get an error: Couldn't find a setf
; expansion for (FUNCALL FN OBJECT).


; What would you suggest I do if I want to 
; pass a the writer method to a function 
; to be funcalled?  (The example is a little 
; contrived - I just am curious about
; error and I'm looking for a workaround). 
; Thanks.

From: Rand Sobriquet
Subject: Re: Funcalling writer methods
Date: 
Message-ID: <1e249696.0311160223.152de30@posting.google.com>
Oh, thanks anyway, but I found a clear post in google groups by Barry
Margolin that describes how to do this.



··········@eudoramail.com (Rand Sobriquet) wrote in message news:<····························@posting.google.com>...
> ; I have a question about funcalling.
> 
> ; Let's say that I have this:
> 
> (defclass test ()
>   ((test-slot :accessor test-slot :initform 'empty)))
> 
> (defun read-slot (fn object)
>   (format t "~A" (funcall fn object)))
> 
> (read-slot #'test-slot (make-instance 'test))
> 
> ; All this works as expected. But when I define:
> 
> (defun set-slot (fn object)
>   (setf (funcall fn object) 'filled))
> 
> 
> ; I get an error: Couldn't find a setf
> ; expansion for (FUNCALL FN OBJECT).
> 
> 
> ; What would you suggest I do if I want to 
> ; pass a the writer method to a function 
> ; to be funcalled?  (The example is a little 
> ; contrived - I just am curious about
> ; error and I'm looking for a workaround). 
> ; Thanks.
From: Paolo Amoroso
Subject: Re: Funcalling writer methods
Date: 
Message-ID: <87brr5rgws.fsf@plato.moon.paoloamoroso.it>
Rand Sobriquet writes:

> Oh, thanks anyway, but I found a clear post in google groups by Barry
> Margolin that describes how to do this.
[...]
> ··········@eudoramail.com (Rand Sobriquet) wrote in message news:<····························@posting.google.com>...
[...]
>> ; What would you suggest I do if I want to 
>> ; pass a the writer method to a function 
>> ; to be funcalled?  (The example is a little 

Can you provide the message ID of Barry's article?


Paolo
-- 
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
From: Rand Sobriquet
Subject: Re: Funcalling writer methods
Date: 
Message-ID: <1e249696.0311220339.33922b8@posting.google.com>
Paolo,

It's a short post:
<··················@burlma1-snr1.gtei.net> 

(Hope that's what a message id looks like. I just searched for
"funcall" and "writer method")


Paolo Amoroso <·······@mclink.it> wrote in message news:<··············@plato.moon.paoloamoroso.it>...
> Rand Sobriquet writes:
> 
> > Oh, thanks anyway, but I found a clear post in google groups by Barry
> > Margolin that describes how to do this.
>  [...]
> > ··········@eudoramail.com (Rand Sobriquet) wrote in message news:<····························@posting.google.com>...
>  [...]
> >> ; What would you suggest I do if I want to 
> >> ; pass a the writer method to a function 
> >> ; to be funcalled?  (The example is a little 
> 
> Can you provide the message ID of Barry's article?
> 
> 
> Paolo
From: Thomas A. Russ
Subject: Re: Funcalling writer methods
Date: 
Message-ID: <ymihe12v74x.fsf@sevak.isi.edu>
··········@eudoramail.com (Rand Sobriquet) writes:

> ; What would you suggest I do if I want to 
> ; pass a the writer method to a function 
> ; to be funcalled?  (The example is a little 
> ; contrived - I just am curious about
> ; error and I'm looking for a workaround). 
> ; Thanks.

You need to actually pass the writer generic function.  This works in
ACL and MCL.  A check of the Hyperspec confirms that (SETF <name>) is
valid as a function name, and therefore is a legal argument to the
FUNCTION special form, and by extension to #'

(setq ii (make-instance 'test))
  ==> #<TEST @ #x469be62>
(test-slot ii)
  ==> EMPTY
(funcall #'(setf test-slot) 'full ii)
  ==> FULL
(test-slot ii)
  ==>

-- 
Thomas A. Russ,  USC/Information Sciences Institute