Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!nntp.sei.cmu.edu!cis.ohio-state.edu!math.ohio-state.edu!cs.utexas.edu!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: <DILIB8.MAI@cunews.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Organization: Carleton University, Ottawa, Canada
References: <494it7$3vl@fs2.abdn.ac.uk>
Date: Sat, 25 Nov 1995 10:54:44 GMT
Lines: 49

In article <494it7$3vl@fs2.abdn.ac.uk>, u01nsc <u01nsc@abdn.ac.uk> wrote:
>Hello,
>
>What is the difference between self and yourself in
>Smalltalk?
>Thanks for any info,
>
>Nick 

'self' is a special word in Smalltalk that refers to the receiver of
the message.  It refers to an object so it can be used as the first
thing in an expression.

'yourself' is a message which can be sent to an object.  In response,
the object returns itself 
i.e.,
    yourself
        ^self

Since it's a message, it can't start an expression - you must have an
object to start the expression.  Yourself is most commonly used in
cascades to insure that the value returned by the cascade is the
receiver of the cascade.  Eg.

   a := OrderedCollection new
       add: 'hello';
       add: 'there

assigns 'there' to a since the last add: returns 'there'.

   a := OrderedCollection new
       add: 'hello';
       add: 'there;
       yourself

assigns an OrderedCollection to a since yourself always returns the
receiver.

David Buck
dbuck@ccs.carleton.ca

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



