From: Kris De Waele
Subject: need help: funcall and accessor methods
Date: 
Message-ID: <#u9LBYX59GA.283@ntdwwaaw.compuserve.com>
I have code like this :

(defclass person ()
    ((name :accessor name
                 :initarg :name)))

(setq a-person (make-instance 'person :name "somebody"))

and now I want to call the accessor methods with funcall

(funcall 'name a-person)
this works, but how can I call the writer method ?
(funcall #'(setf name) a-person "a different person") ;??

thanks in advance
Kris De Waele

From: Lieven Marchand
Subject: Re: need help: funcall and accessor methods
Date: 
Message-ID: <6u8t89$pn2$1@xenon.inbe.net>
"Kris De Waele" <···········@compuserve.com> writes:

> I have code like this :
> 
> (defclass person ()
>     ((name :accessor name
>                  :initarg :name)))
> 
> (setq a-person (make-instance 'person :name "somebody"))
> 
> and now I want to call the accessor methods with funcall
> 
> (funcall 'name a-person)
> this works, but how can I call the writer method ?
> (funcall #'(setf name) a-person "a different person") ;??

(funcall #'(setf name) "a different person" a-person)

This inversion of arguments may seem to be a bit surprising since you 
can use (setf (name a-person) "a different person")

This is the normal way of defining setf-expanders although #'(setf name) 
is a generic function in this case.

HTH

-- 
Lieven Marchand <···@bewoner.dma.be> 
------------------------------------------------------------------------------
Few people have a talent for constructive laziness. -- Lazarus Long
From: Barry Margolin
Subject: Re: need help: funcall and accessor methods
Date: 
Message-ID: <6ywN1.43$LN.735137@burlma1-snr1.gtei.net>
In article <···············@ntdwwaaw.compuserve.com>,
Kris De Waele <···········@compuserve.com> wrote:
>and now I want to call the accessor methods with funcall
>
>(funcall 'name a-person)

(funcall #'name a-person)

is preferable, although both will work.

>this works, but how can I call the writer method ?
>(funcall #'(setf name) a-person "a different person") ;??

See p.128 of CLtL2, which describes how SETF functions are called: "The
first argument is the new value and the remaining arguments are the values
of the remaining elements of <place>."  So the correct call is:

(funcall #'(setf name) "a different person" a-person)

The order seems to be "backward" because a <place> form may have many
elements; the new value has to be in a fixed position to make it possible
to deal with &optional, &rest, or &key parameters in <place>.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.