Changing strings

jennyw jennyw at dangerousideas.com
Sun Apr 21 21:14:28 UTC 2002


Sorry for the two nearly identical postings ... my mail program died when 
I sent the first one, so I thought it didn't go out.

Another comment on strings ...

The way I'm getting around this is to use the copy method:

   a := 'squeak' copy.

or define a method like

   setA: aString
      a := aString copy

Is this the common practice?

Jen


On Sun, Apr 21, 2002 at 01:33:55PM -0700, jennyw wrote:
> I'm just getting back into Smalltalk after 10 years, so please pardon me
> if this is a well-known topic.
> 
> a := 'squeak'.
> 'squeak' at: 6 put: $l.
> 
> I've noticed that the above code results in a equaling 'squeal'. This 
> seems kind of strange to me.  It seems that literal strings, like symbols, 
> are unique?  I'm not certain, but I don't think all Smalltalks are like 
> this.
> 
> I did notice that:
> 
> a := 'squeak'.
> b:= 'squeal'.
> 'squeak' at: 6 put: $l.
> a == b.
> 
> returns false, so I guess it may not be a problem very often.  
> Nonetheless, I find it disturbing that if a an instance variable is 
> initialized using a string literal, and if a user knows what that string 
> literal is, then the user can change the value of that instance variable 
> without an accessor.
> 
> Any comments?
> 
> Thanks!
> 
> Jen
> 
> 
> 



More information about the Squeak-dev mailing list