Thread View: comp.lang.clos
2 messages
2 total messages
Started by Jeffrey B Kane
Wed, 28 Oct 1992 20:49
passing accessors to functions
Author: Jeffrey B Kane
Date: Wed, 28 Oct 1992 20:49
Date: Wed, 28 Oct 1992 20:49
13 lines
740 bytes
740 bytes
I have an question:
I have a common function that can act on any of a number of
slots of a given class. How can I define a function such that
I can pass it an accessor, the class instance, and the arguments
something like:
(defun do-proc (anAccessor aclass arg)
(setf (anAccessor aclass) arg))
Jeffrey
Re: passing accessors to functions
Author: Barry Margolin
Date: Thu, 29 Oct 1992 04:06
Date: Thu, 29 Oct 1992 04:06
25 lines
1311 bytes
1311 bytes
In article <Bwun61.E1q@world.std.com> jbk@world.std.com (Jeffrey B Kane) writes:
>I have a common function that can act on any of a number of
>slots of a given class. How can I define a function such that
>I can pass it an accessor, the class instance, and the arguments
>something like:
>(defun do-proc (anAccessor aclass arg)
> (setf (anAccessor aclass) arg))
You can't do precisely that. You can pass a slot name, and then use SETF
of SLOT-VALUE, e.g.
(defun do-proc (slot-name object arg)
(setf (slot-value object slot-name) arg))
or you can pass the setf function itself:
(defun do-proc (assignment-function object arg)
(funcall assignment-function arg object))
This would be called as (do-proc #'(setf <slot-name>) <object> <value>).
--
Barry Margolin
System Manager, Thinking Machines Corp.
barmar@think.com {uunet,harvard}!think!barmar
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads