looking for answers to exercises in Squeak book Ch 2.

Tim Olson tim at jump.net
Fri Apr 27 12:29:13 UTC 2001


>Thomas Porter <txporter at mindspring.com> wrote:
>	I assume that my assignment of "aString := 'squeak'" merely created a 
>variable,
>
>	If this is the case, then how do I ever assign a variable which
>	was initialized to a literal with a new value:
>	
>	aString := 'foo'.
>	aString := 'bar'.
>	
>	if the variable merely points to the literal?

Richard's reply hopefully cleared up any confusion you might have here 
regarding variable assignments.  If you want to use a literal to 
initialize a variable that you want to be mutable, you should use 'copy':

     aString := 'Squeak' copy.
     aString at: 4 put: $a.


     -- Tim Olson





More information about the Squeak-dev mailing list