From: Andreas Politz
Subject: programatically constructing the #'(setf accessor) function
Date: 
Message-ID: <1233492491.409207@arno.fh-trier.de>
Hi,

assuming there is class foo with slot and accessor 'attribute'.
This makes it possible to read the value

(let ((reader 'attribute))
   (funcall reader (make-instance 'foo)))

. But how do I best get at the corresponding #'(setf attribute) method
? Currently I am doing it like in the following code, but have a bad
feeling about it.

(defclass foo nil
   ((attribute
     :accessor attribute
     :initform 0)))

(defun make-undo-fn (object accessor)
   (let ((value (funcall accessor object)))
     (eval `(lambda nil
              (funcall #'(setf ,accessor)
                       (quote ,value)
                       ,object)))))

(setf obj (make-instance 'foo)
       undo-fn (make-undo-fn obj 'attribute))

(attribute obj)
=> 0

(setf (attribute obj) 42)
=> 42

(funcall undo-fn)
=> 0

(attribute obj)
=> 0

-ap

From: Tobias C. Rittweiler
Subject: Re: programatically constructing the #'(setf accessor) function
Date: 
Message-ID: <87tz7e8g6t.fsf@freebits.de>
Andreas Politz <·······@fh-trier.de> writes:

> Hi,
>
> assuming there is class foo with slot and accessor 'attribute'.
> This makes it possible to read the value
>
> (let ((reader 'attribute))
>   (funcall reader (make-instance 'foo)))
>
> . But how do I best get at the corresponding #'(setf attribute) method
> ? Currently I am doing it like in the following code, but have a bad
> feeling about it.

(FDEFINITION `(setf ,attribute))

  -T.
From: Andreas Politz
Subject: Re: programatically constructing the #'(setf accessor) function
Date: 
Message-ID: <1233528192.816038@arno.fh-trier.de>
Tobias C. Rittweiler wrote:
> Andreas Politz <·······@fh-trier.de> writes:
> 
>> Hi,
>>
>> assuming there is class foo with slot and accessor 'attribute'.
>> This makes it possible to read the value
>>
>> (let ((reader 'attribute))
>>   (funcall reader (make-instance 'foo)))
>>
>> . But how do I best get at the corresponding #'(setf attribute) method
>> ? Currently I am doing it like in the following code, but have a bad
>> feeling about it.
> 
> (FDEFINITION `(setf ,attribute))
> 
>   -T.

Thanks !

-ap