String literal at:put: question

Lex Spoon lex at cc.gatech.edu
Sun Dec 31 17:41:56 UTC 2000


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.  :|

(I at least *tried* to make Float's and Characters read-only, too, though
I don't remember how far I got!)

-Lex



Hans-Martin Mosner <hm.mosner at cityweb.de> wrote:
> Avi Schwartz wrote:
> 
> > Hi,
> >
> > I am new to Smalltalk and Squeak, so please bear with me...
> 
> Welcome to The Club :-)
> 
> > I am trying to figure out why the result of
> >
> > 'abcdef' at: 1 put: $x
> >
> > is $x and not 'xbcdef'.
> 
> That has been the Smalltalk behavior since the dark ages... I presume
> the intention is to make it semantically similar to assignment
> expressions, whose value is equal to the assigned value. To achieve your
> intention, you should evalutae
>     'abcdef'
>         at: 1 put: $x;
>         yourself
> which returns the receiver of the first message expression.
> 
> > Now, to complicate matters even worse for me, according to the book
> > 'Smalltalk, Objects, and Design' by Chamond Liu, the result I should
> > expect is an exception since a string literal is immutable.
> 
> Squeak does not currently have really immutable objects (with the
> exception of SmallIntegers). This is also true for a number of other
> Smalltalks. To make your code portable to Smalltalks with immutable
> literals, you should write
>     'abcdef' copy
>         at: 1 put: $x;
>         yourself
> It would certainly be a great service to the Squeak community to
> implement immutable objects, but I think that this requires quite some
> in-depth knowledge of the VM and/or image to do, so this is certainly
> not a beginner's project.
> 
> Cheers and happy holidays,
> Hans-Martin





More information about the Squeak-dev mailing list