Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!oitnews.harvard.edu!news.dfci.harvard.edu!camelot.ccs.neu.edu!chaos.dac.neu.edu!usenet.eel.ufl.edu!tank.news.pipex.net!pipex!howland.reston.ans.net!torn!nott!cunews!dbuck
From: dbuck@superior.carleton.ca (Dave Buck)
Subject: Re: Yourself
X-Nntp-Posting-Host: superior.carleton.ca
Message-ID: <DG00vK.7EH@cunews.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Organization: Carleton University, Ottawa, Canada
References: <150326Z05101995@anon.penet.fi>
Date: Thu, 5 Oct 1995 23:21:20 GMT
Lines: 55

In article <150326Z05101995@anon.penet.fi>,
The Unknown Ranger <an397723@anon.penet.fi> wrote:
>>>anArray := Array with: 10@20 with: 20@10.
>>>anArray := (Array new: 2) at: 1 put: 10@20; at: 2 put: 20@10.
>>
>>Also, your second line won't work.  You need to add a ";yourself" at
>>the end of the line before the period.
>
>I tried both of these. The first returned the entire array. The second 
>returned only the 20 @ 10.  Are you saying that adding ";yourself" will 
>return the entire array in the second example?  I'm confused between self 
>and yourself.

That's right.  It works like this:  the word 'self' is a special word
in Smalltalk that refers to the receiver of the message.  'self' is
never used as the name of a method (anyone who does this should be
shot).  The word 'yourself' refers to a method that all objects
understand.  The implementation is something like:

yourself
    ^self

Hence, you can always send 'yourself' to an object and it will return
itself.  My, how useful.  Well, actually, it is useful.  In cascades
(semicolons), you often want to send a few messages to an object then
return the object.  But the result of a cascade is the result of the
last message in the cascade.  If your last message returned something
other than the receiver, you son't get what you want.

eg.

c := OrderedCollection new
       add: 5;
       add: 7.

Any method for collections that writes into the collection returns the
thing that was written, not the collection.  So, in this case, c will
be 7.  If you wanted to assign the collection into c, you need to end
the cascade with a message that guarantees that it will return the
receiver.  That's what yourself does.

c := OrderedCollection new
       add: 5;
       add: 7;
       yourself

David Buck
dbuck@ccs.carleton.ca

_________________________________
| David K. Buck                 |
| dbuck@ccs.carleton.ca         |
| The Object People             |
|_______________________________|

