Article View: comp.lang.clos
Article #3Re: passing accessors to functions
From: 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
Technical Details
Message-ID:
<1cnnvlINNbci@early-bird.think.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!think.com!barmarReferences:
<Bwun61.E1q@world.std.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.clos Subject: Re: passing accessors to functions Date: 29 Oct 1992 04:06:13 GMT Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 25 Message-ID: <1cnnvlINNbci@early-bird.think.com> References: <Bwun61.E1q@world.std.com> NNTP-Posting-Host: gandalf.think.com Keywords: ACCESSORS FUNCTIONS