Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!pa.dec.com!jrdzzz.jrd.dec.com!tkou02.enet.dec.com!jit533!diamond From: diamond@jit533.swstokyo.dec.com (Norman Diamond) Newsgroups: comp.object Subject: Re: value semantic versus reference semantic Keywords: Smalltalk, distribution, values, object identity, immutability Message-ID: <1991May21.022551.5396@tkou02.enet.dec.com> Date: 21 May 91 02:25:51 GMT References: <68780001@hpcupt1.cup.hp.com> <1991May14.093053.3017@jyu.fi> <3683@sequent.cs.qmw.ac.uk> Sender: usenet@tkou02.enet.dec.com (USENET News System) Reply-To: diamond@jit533.enet@tkou02.enet.dec.com (Norman Diamond) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 39 In article <3683@sequent.cs.qmw.ac.uk> eliot@cs.qmw.ac.uk (Eliot Miranda) writes: >More than that. In systems like Smalltalk with many reflective facilities >you must also think hard about e.g. allInstancesDo:. Its no good not being >able to distinguish between two immutable objects with the same value if you >can demonstrate that in fact more than one exists. e.g. in Smalltalk, >if running the following > | count | > count := 0. > ImmutableStringValue allInstancesDo: [:s| > (s size = 3 > and: [(s at: 1) = $Y > and: [(s at: 2) = $E > and: [(s at: 3) = $S]]]) ifTrue: [ > count := count + 1]]. > count >evaluates to something more than 1 then your implementation of immutable values >is flawed. I haven't thought of a good solution to this. By this reasoning, your implementation of immutable values is flawed if count evaluates to something LESS than 1, too. I think there are a lot of types (or classes or many other categories of objects) for which there are an infinite number of immutable VALUES, though only a few of these values are actually assigned to objects at any given time. Now, if you want to perform some operation on the values that are actually assigned to objects, then allInstancesDo: will do that. You probably want to repeat your operation on all equal (pseudo-equivalent) instances. I don't see any problem there. If you want a count of how many objects are assigned the same value, then allInstancesDo: will not be sufficient -- but it never was. If you want to know whether any object is assigned the value, then compare count to 0. If you want to know whether a value is a value, the answer is always yes. I don't think you should have to insist on count evaluating to 1. -- Norman Diamond diamond@tkov50.enet.dec.com If this were the company's opinion, I wouldn't be allowed to post it. Permission is granted to feel this signature, but not to look at it.