f



Attempt to update read-only object

From The Dolphin Smalltalk Companion, page 15:

Put this in a workspace and DisplayIt:

testString := 'dolphin smalltalk'.
testString at: 1 put: $D;
	        at: 9 put: $S.
testString

I get "Attempt to update read-only object". I browsed the class reference; at:put: exist for strings just fine; String::at:put: has a <primitive-64> compiler declaration in it (which makes sense for such basic objects!).

Windows 10 x64, DS 7.0.5
Is there something silly in these few lines I'm not seeing? Sorry for the silly question. I'll try to duplicate on another machine in a few hours.

-Travis
0
Travis
9/30/2016 2:16:09 PM
comp.lang.smalltalk.dolphin 3769 articles. 0 followers. Post Follow

6 Replies
212 Views

Similar Articles

[PageSpeed] 47

I get the same error on Win7x64

On Friday, September 30, 2016 at 7:16:09 AM UTC-7, Travis Ayres wrote:
> From The Dolphin Smalltalk Companion, page 15:
> 
> Put this in a workspace and DisplayIt:
> 
> testString := 'dolphin smalltalk'.
> testString at: 1 put: $D;
> 	        at: 9 put: $S.
> testString
> 
> I get "Attempt to update read-only object". I browsed the class reference; at:put: exist for strings just fine; String::at:put: has a <primitive-64> compiler declaration in it (which makes sense for such basic objects!).
> 
> Windows 10 x64, DS 7.0.5
> Is there something silly in these few lines I'm not seeing? Sorry for the silly question. I'll try to duplicate on another machine in a few hours.
> 
> -Travis

0
Travis
9/30/2016 6:23:45 PM
On Friday, September 30, 2016 at 11:23:46 AM UTC-7, Travis Ayres wrote:
> I get the same error on Win7x64
> 
> On Friday, September 30, 2016 at 7:16:09 AM UTC-7, Travis Ayres wrote:
> > From The Dolphin Smalltalk Companion, page 15:
> > 
> > Put this in a workspace and DisplayIt:
> > 
> > testString := 'dolphin smalltalk'.
> > testString at: 1 put: $D;
> > 	        at: 9 put: $S.
> > testString
> > 
> > I get "Attempt to update read-only object". I browsed the class reference; at:put: exist for strings just fine; String::at:put: has a <primitive-64> compiler declaration in it (which makes sense for such basic objects!).
> > 
> > Windows 10 x64, DS 7.0.5
> > Is there something silly in these few lines I'm not seeing? Sorry for the silly question. I'll try to duplicate on another machine in a few hours.
> > 
> > -Travis

I think there was a problem with the VM; see
https://github.com/dolphinsmalltalk/Dolphin/issues/234
0
Travis
9/30/2016 7:26:14 PM
I think this is intended behaviour, to have the literal string as read-only.
To modify string, first make a copy of it.
Ie: cange the first line to:
    testString := 'dolphin smalltalk' copy. 
0
Richard
10/2/2016 1:16:31 PM
On Sunday, October 2, 2016 at 6:16:38 AM UTC-7, Richard Ronteltap wrote:
> I think this is intended behaviour, to have the literal string as read-only.
> To modify string, first make a copy of it.
> Ie: cange the first line to:
>     testString := 'dolphin smalltalk' copy.

That does make sense. I wonder if that's the case? Literals being read only is very reasonable...

Is anybody sure one way or the other?

Thanks,
-Travis
0
Travis
10/4/2016 10:09:27 PM
Yes, method and expression literals are immutable in Dolphin 6 and higher. =
This is a useful precaution since, if you modify a literal in a method, the=
 source of the method will still show the original value but when evaluated=
 the method will use the modified value.=20

You'll get the same error with Array literals:

#('test') at: 1 put: 'tst'

Again, using a copy will work since the copy is not immutable.


On Wednesday, October 5, 2016 at 12:09:33 AM UTC+2, Travis Ayres wrote:
> On Sunday, October 2, 2016 at 6:16:38 AM UTC-7, Richard Ronteltap wrote:
> > I think this is intended behaviour, to have the literal string as read-=
only.
> > To modify string, first make a copy of it.
> > Ie: cange the first line to:
> >     testString :=3D 'dolphin smalltalk' copy.
>=20
> That does make sense. I wonder if that's the case? Literals being read on=
ly is very reasonable...
>=20
> Is anybody sure one way or the other?
>=20
> Thanks,
> -Travis

0
john
10/5/2016 7:41:31 AM
Thank you, this very much makes sense; glad I asked, as parts of the book a=
re a  little outdated...

Still good stuff and I wish there were more Dolphin Smalltalk books :(

On Wednesday, October 5, 2016 at 12:41:32 AM UTC-7, John Aspinall wrote:
> Yes, method and expression literals are immutable in Dolphin 6 and higher=
.. This is a useful precaution since, if you modify a literal in a method, t=
he source of the method will still show the original value but when evaluat=
ed the method will use the modified value.=20
>=20
> You'll get the same error with Array literals:
>=20
> #('test') at: 1 put: 'tst'
>=20
> Again, using a copy will work since the copy is not immutable.
>=20
>=20
> On Wednesday, October 5, 2016 at 12:09:33 AM UTC+2, Travis Ayres wrote:
> > On Sunday, October 2, 2016 at 6:16:38 AM UTC-7, Richard Ronteltap wrote=
:
> > > I think this is intended behaviour, to have the literal string as rea=
d-only.
> > > To modify string, first make a copy of it.
> > > Ie: cange the first line to:
> > >     testString :=3D 'dolphin smalltalk' copy.
> >=20
> > That does make sense. I wonder if that's the case? Literals being read =
only is very reasonable...
> >=20
> > Is anybody sure one way or the other?
> >=20
> > Thanks,
> > -Travis

0
Travis
10/28/2016 5:31:16 AM
Reply: