Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!unido!tub!db0tui11!muhrth From: MUHRTH@tubvm.cs.tu-berlin.de (Thomas Muhr) Newsgroups: comp.lang.smalltalk Subject: Re: Question on Ordered Collections Message-ID: <90039.113838MUHRTH@DB0TUI11.BITNET> Date: 8 Feb 90 10:38:38 GMT References: <1045@prlhp1.prl.philips.co.uk> Distribution: comp.lang.smalltalk Organization: Technical University Berlin Lines: 70 In article <1045@prlhp1.prl.philips.co.uk>, krause@prlhp1.prl.philips.co.uk (krause) says: > >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 default return-object of every method is the instance which the message is sent to. If you want anything else than the instance you must specify what is to be returned with the caret ^. The semantics of message-returns seems to be a bit nonsystematic in ST, for instance the add: method for OrderedCollections: it returns the object added!. So to come around this, you have to send as the last message in a cascade of messages one which returns the object all the previous messages were sent to. And this last message is 'yourself' - you have noticed that it is of the simple sort - it does nothing except redirecting the pointer to what you want, despite of what previous messages return. It is often used in the creation of panes within an open method. Before you addSubPane to a TopPane, which you have sent messages not returning the TopPane, you better send a 'yourself' as last message to the TopPane: topPane:= (TopPane new model:xxxxx; label:nnnnn;.......;yourself). topPane addSubpane: spspspsp. (I am an eager student of this newsgroup....) So long - Thomas > >David >----- ------- Thomas Muhr, Technical University of Berlin, BITNET: muhrth@db0tui11 Project ATLAS - Computer Based Tools for Qualitative Research "Computers, like every technology, are a vehicle for the transformation of tradition." (WINOGRAD/FLORES)