string sharing (possible bug?)

Andreas Raab raab at isgnw.CS.Uni-Magdeburg.De
Wed Dec 9 15:47:33 UTC 1998


> If this is the
> correct behaviour, then I suppose a good Smalltalk programming rule
> would be, "don't modify an array or string object that has been
> initialized from a constant",

Replace "array or string object" by "literal" and you are absolutely
right. BTW, if you're modifying a literal array/string then the problem
is even worse than you might think, as for example in the following
method:

hackLiteralArray
  | array |
  array _ #(0 2).
  array at: 1 put: (array at: 1) + 1.
  ^array

If you call this method repeatedly it will return

  #(1 2)
  #(2 2)
  #(3 2)
  ...

but the source code will still look the same.

> But that just doesn't seem right to me.

Well, unfortunately that's the way it is ... 

> I know that symbols are all unique, but I didn't know
> that string and array constants are also unique.

That depends on the Parser - it tries to minimize the literals in methods
for a more compact representation (which is usually a good thing).

  Andreas
-- 
Linear algebra is your friend - Trigonometry is your enemy.
+===== Andreas Raab ============= (raab at isg.cs.uni-magdeburg.de) =====+
I Department of Simulation and Graphics      Phone: +49 391 671 8065  I
I University of Magdeburg, Germany           Fax:   +49 391 671 1164  I
+=============< http://isgwww.cs.uni-magdeburg.de/~raab >=============+





More information about the Squeak-dev mailing list