String literal at:put: question
Andrew P. Black
black at cse.ogi.edu
Mon Jan 1 03:20:04 UTC 2001
>Actually, it's not too hard to create a ReadOnlyString and ReadOnlyArray
>which have several methods overridden to produce errors. Overriding at:
>and basicAt: goes an awefully long way. Then, the Parser needs to be
>updated. I did this once, but it was in an image too divergent from the
>main Squeak image that it could really be useful. :|
Is it necessary to change the parser?
I had been thinking instead about changing the behavior of class
String so that Strings are immutable (by redefining at:put:,
replaceFrom:to:with:startingAt:, byteAt:put: and what else?), and
creating a separate class MutableString for those few places where
string mutation is really used. I wonder how common this behavior is.
One tricky thing is that string mutation is sometimes used to create
a string that will then be treated as immutable. See, for example,
Symbol asString. This could (and probably should) be changed to use
String withAll: aSymbol. Mutating a string is OK while it is being
constructed (how else could it be constructed?, but taboo once it has
been handed off to the world.)
Andrew
More information about the Squeak-dev
mailing list
|