Strings
jennyw
jennyw at dangerousideas.com
Sun Apr 21 20:27:31 UTC 2002
I'm just getting back into Smalltalk after 10 years, so pardon if I'm
bringing up something that may seem obvious to you.
This code:
a := 'squeak'.
'squeak' at: 6 put: $l.
causes the value of a to change to 'squeal'. I understand how this is
happening (there is only one instance of a string literal in squeak, as
with symbols; I don't think this is true of all Smalltalks, but I could be
wrong), but I don't understand why it was designed this way. It just seems
kind of odd to me.
Perhaps it's usually not a problem? I do notice that:
a := 'squeak'.
b := 'squeal'.
a at: 6 put: $l.
a == b
returns false.
Nontheless, it kind of spooked me to learn that if an instance variable
received its value from a string literal (e.g. via an accessor or in
initialization) that the value of that variable could change if someone
typed something like 'string' at: 1 put: $x.
Any comments?
Thanks!
Jen
More information about the Squeak-dev
mailing list
|