Article View: comp.lang.clos
Article #691Re: Automatic evaluation of expression in CLOS slots
From: Gregor Kiczales
Date: Mon, 04 Jan 1993 17:40
Date: Mon, 04 Jan 1993 17:40
45 lines
2746 bytes
2746 bytes
In article <1993Jan3.023306.25733@cc.umontreal.ca> kardank@ERE.UMontreal.CA (Kardan Kaveh) writes: I would like to be able to place expressions in class slots, and have them transparently evaluated when accessed. Is there a standard way of doing this? Do I need the Meta Object Protocol for this? And then, in article <1i7g64INN2tt@early-bird.think.com> barmar@think.com (Barry Margolin) writes: To get precisely what you described in your example, you need the MOP. If you're willing to allow SLOT-VALUE to return the expression, but have SLOT-1 perform the computation, you can do this without the MOP. You could write... I think this should be sufficient, since functions outside the class should not use SLOT-VALUE instead of the accessor function. I want to make a brief comment about this, having to do with how I think one should go about making this decision. That is, how does one decide, for a given application, whether the approach proposed by Barmar is good enough or whether one wants to use the MOP to change the behavior of slot-value. I believe the way to think about this is to enumerate to yourself all the different `calls' to slot-value there are, and decide whether you want all of those calls to perform the special action (i.e. evaluate the form) or whether it is ok for some of them just return the value in the slot. The key point is that the calls to slot-value that come from calling an accessor are not the only calls to slot-value -- various environment tools like inspectors (e.g. describe) also call slot-value. So, if all you want is for calls to certain accessors (i.e. slot-1) to perform the special action, Barmar's proposed solution works fine. But, it means that any other tool that just calls slot-value -- notably describe and other kinds of inspectors -- won't perform the special action, they will just return the raw value in the slot. That may be unnacceptable to you, and it is for cases where that is unnacceptable that this part of the MOP is provided. It really depends on what you want. Gregor
Technical Details
Message-ID:
<GREGOR.93Jan4094044@tracer-bullet.parc.xerox.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!usc!sdd.hp.com!saimiri.primate.wisc.edu!ames!biosci!parc!gregorReferences:
<1993Jan3.023306.25733@cc.umontreal.ca> <1i7g64INN2tt@early-bird.think.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!usc!sdd.hp.com!saimiri.primate.wisc.edu!ames!biosci!parc!gregor From: gregor@parc.xerox.com (Gregor Kiczales) Newsgroups: comp.lang.clos Subject: Re: Automatic evaluation of expression in CLOS slots Message-ID: <GREGOR.93Jan4094044@tracer-bullet.parc.xerox.com> Date: 4 Jan 93 17:40:44 GMT References: <1993Jan3.023306.25733@cc.umontreal.ca> <1i7g64INN2tt@early-bird.think.com> Sender: news@parc.xerox.com Followup-To: comp.lang.clos Organization: Xerox Palo Alto Research Center Lines: 45 In-Reply-To: barmar@think.com's message of 3 Jan 93 19:52:36 GMT