Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.sprintlink.net!newsfeed.internetmci.com!chi-news.cic.net!uwm.edu!spool.mu.edu!torn!nott!cunews!dbuck
From: dbuck@superior.carleton.ca (Dave Buck)
Subject: Re: Smalltalk Question
X-Nntp-Posting-Host: superior.carleton.ca
Message-ID: <DGqv5v.MwL@cunews.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Organization: Carleton University, Ottawa, Canada
References: <466uq3$jjr@steel.interlog.com>
Date: Fri, 20 Oct 1995 11:13:07 GMT
Lines: 54

In article <466uq3$jjr@steel.interlog.com>, K Shiu <kens@interlog.com> wrote:
>It seems to me that I will get identical result in the following 2 lines:
>
>	a := b.
>	a become: b.
>
>where b is not Integer. a will point to the same object that b is pointing to.
>
>Would anybody tell me if there is any difference between := and #become:?
>

Cpnsider the following example:

   a := 'hello'.
   b := 'world'.
   c := a.

If we now use:
   a := b
we get:
     a    'world'
     b    'world'
     c    'hello'

If instead we used
   a become: b
we get:

     a    'world'
     b    'hello'
     c    'world'

(it works this way in VisualWorks which has a 2-way become.  Visual
Smalltalk as far as I know will set all three to 'world')

The := means 'make this variable point to this object'.
becomes: means 'make every object in the system that points to the
receiver point to the parameter instead and make every object in the
world that points to the parameter point to the receiver'.  It
effectively swaps the identity of the two objects.

The becomes: method should be used with great care in rare conditions
(in normal programming).  It shouldn't be used in normal everyday
code.

David Buck
dbuck@ccs.carleton.ca

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

