Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!news.kei.com!nntp.coast.net!harbinger.cc.monash.edu.au!news.bhp.com.au!mel.dit.csiro.au!actcsiro!news.nsw.CSIRO.AU!metro!metro!news.cs.su.oz.au!tmx!news.tmx.com.au!news
From: Stephan Meyn <s.meyn@oose.com.au>
Subject: Re: sets of objects
Message-ID: <311AC141.555F@oose.com.au>
Nntp-Posting-Host: 203.5.19.198
Sender: news@online.tmx.com.au (System Administrator)
Mime-Version: 1.0
X-Mailer: Mozilla 2.0b6a (WinNT; I)
Content-Type: text/plain; charset=us-ascii
Organization: Object Oriented Pty Ltd
Date: Fri, 9 Feb 1996 03:36:33 GMT
References: <4fd1f5$pir@iii2.iii.net>
Content-Transfer-Encoding: 7bit
Lines: 35

Robert M Rogers Jr wrote:
> 
> What must be implemented to allow the Set class to understand when anObject
> is already contained in the set. Expected behaviour is observed for
> integers and strings but application objects are not.
> 
> Class: Person
> Attribute: name
> Attribute: age
> method: name: aString
> method: age: anInteger
> 
> Friends := Set new.
> 
> | f1 f2 |
> f1 := Person new.
> f1 := Person new.
> f1 name: 'Me'; age: 60.
> f2 := Person new.
> f2 name: 'You'; age: 55.
> Friends add: f1; add: f2.
> 
> If I execute this code segement repeatly it results in the addition of
> two aPerson elements each time. I desire the behaviour to recognize
> that the elements are already present in the set. Why is this not
> straight forward?
> 
> ,RedWhat you have omitted is to instruct the Person class how to identify that two 
instances of Person are actually the same: ie you need to implement '='. At
this stage it is not straightforward for Smalltalk to derive that having
in the instance variables of two instances the same values (not same instances tho!) 
equates to them being equal.

cheerio
stephan
