From: Thomas A. Russ
Subject: Re: Setting a value programatically given the name of an accessor.
Date:
Message-ID: <ymiejpkcijo.fsf@sevak.isi.edu>
Madhu <·······@meer.net> writes:
> Helu. Given the name of an accessor, how best to set the value
> programatically? For example:
...
> * (defun setslot (object slot-name new-value)
> (funcall (fdefinition `(setf ,slot-name)) new-value object ))
> SETSLOT
...
> Is this (i.e. guessing the setf function name, and funcalling its
> fdefinition) the only route available? Do you know any other way to do
> this?
Not in any portable fashion for DEFSTRUCT slots.
If you use CLOS, then you can use SLOT-VALUE which is SETF-able:
(setf (slot-value object slot-name) new-value)
Some Common Lisp implementations use CLOS for structures and there
slot-value will work for defstruct object, but there is no reason to
believe this has to be so.
--
Thomas A. Russ, USC/Information Sciences Institute