Path: utzoo!attcan!uunet!snorkelwacker!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!mephisto!udel!new From: new@udel.edu (Darren New) Newsgroups: comp.lang.smalltalk Subject: Re: Question on Ordered Collections Message-ID: <10271@nigel.udel.EDU> Date: 6 Feb 90 13:22:56 GMT References: <1045@prlhp1.prl.philips.co.uk> Sender: usenet@udel.EDU Reply-To: new@udel.edu (Darren New) Distribution: comp.lang.smalltalk Organization: University of Delaware Lines: 31 In article <1045@prlhp1.prl.philips.co.uk> krause@prlhp1.UUCP () writes: @ Fred <- OrderedCollection new @ add: 'anItem'; @ add: 'anOtherItem'; @ add: 'finalItem' @Fred will NOT be an ordered collection, but a string. The value assigned to Fred is the value returned from the final add: message. If you examine add:, you will see that it returns its argument, not self. @ Fred <- OrderedCollection new @ add: 'anItem'; @ add: 'anOtherItem'; @ add: 'finalItem'; @ yourself @Will result in Fred becoming an ordered collection. yourself, not containing a return, defaults to returning self. Thus, the new OrderedCollection is returned and assigned to Fred. @ Fred <- OrderedCollection new. @ Fred add: 'anItem'; @ add: 'anOtherItem'; @ add: 'finalItem' Here, you ignore the vale returned from the add: call and get what you expect. I think it is believed that the argument to add: is more often needed after adding than the Collection is; hence, add: returns its argument. This kind of stuff is often a gotcha and IMHO makes Smalltalk harder to master (but of course more flexible). Happy Hacking! Darren