Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!rutgers!apple!netcom!schang From: schang@netcom.UUCP (Sehyo Chang) Newsgroups: comp.lang.smalltalk Subject: Re: Question on Ordered Collections Message-ID: <6696@netcom.UUCP> Date: 6 Feb 90 17:21:27 GMT References: <1045@prlhp1.prl.philips.co.uk> Distribution: comp.lang.smalltalk Organization: NetCom- The Bay Area's Public Access Unix System {408 249-0290 guest} Lines: 55 In article <1045@prlhp1.prl.philips.co.uk> krause@prlhp1.UUCP () writes: >Hi, > >A quick smalltalk question. > >If you code something like: > > Fred <- OrderedCollection new > add: 'anItem'; > add: 'anOtherItem'; > add: 'finalItem' > >Fred will NOT be an ordered collection, but a string. > ------ > >coding: > > Fred <- OrderedCollection new > add: 'anItem'; > add: 'anOtherItem'; > add: 'finalItem'; > yourself > >Will result in Fred becoming an ordered collection. The funny thing is that yourself >is a method that does nothing. I even coded up a dummy method for ordered collection >and used that instead of yourself .... this resulted in Fred being correct. > >Code like > > Fred <- OrderedCollection new. > Fred add: 'anItem'; > add: 'anOtherItem'; > add: 'finalItem' > > >works as I currently expect. > >Has anyone any comments or suggestions? Exactly WHAT IS OCCURING? > >I have smalltalk version 2.3 running on an Apollo. > > The method 'yours' does something. It returns 'sender'. When you have cascading message like "OrderedCollection new; add: 'anItem' ", the result of expression is result of last expression in the cascade message. Thus result will be method "add: 'anItem'". If you browse through class 'OrderedCollection' it will evaluate argument(string in this case) instead of the OrderedCollection. Second example works as you expected because you already assigned collection to the variable and doesn'depended on side effects of evaluation. -- Sehyo Chang schang@netcom.uucp Ascent Logic Corp. (408)943-0630