|
Re: question on differences between images: msg#00204lang.smalltalk.squeak.beginners
Hi! > I've been playing a little bit more with Squeak, and I found another > strange (to me; please, consider that I am still a newbie) thing. > In some lectures by Stephane Ducasse there is an example illustrating the > difference between literal arrays and arrays created with new:. In > particular, > adding the following method to class SmallInteger: > > m1 > > | anArray | > anArray := #( nil ). > (anArray at: 1) isNil > ifTrue: [ Transcript show: 'Put 1'; cr. anArray at: 1 put: 1. ] > > and executing > > 1 m1 > > should display the message 'Put 1' only once. And this is how it works... > in image 3.9 Odd code though. Arrays created using the literal syntax "#( blab bla )" should not be modified - it is very bad style. The Array is created at *compile time*, not on method activation time. This is why it only has nil in it the first time you call #m1. > But if we repeat the experiment in image 3.0, it displays nothing in the > Transcript (not even the first execution). Again, I am puzzled by this > behavior (I am always assuming that these experiments that behave > differently > in different Squeak images are standard Smalltalk). First of all - Squeak is not a "dead" implementation of Smalltalk-80 or ANSI X3J20. It evolves. The recent largest change is of course the addition of Traits in version 3.9. In this case you are seeing a difference in how literal Arrays are parsed. I don't have a 3.0 image handy but I bet that if you do an "inspect it" on: #( nil ) ...you will seen an instance of Array with a Symbol in it, *NOT* nil. The Symbol #nil is not the same thing as the object referenced by nil (the sole instance of class UndefinedObject). :) I have a recollection that the parsing of literal Arrays was changed relatively recently, perhaps it was in 3.9 even (or 3.8), so that the special case of "nil" was parsed into a reference to the object nil, and not parsed into a Symbol. I also vaguely recall that this created lots of interesting problems in old code - but I think it was reasonably worked out. > One more thing. Perhaps there is people wondering why someone should worry > about the behavior of an old image. The answer is that I am using a > stripped > version of image 3.0 to play with Squeak on a Jornada 720. More recent > complete > images are too heavy for the J720 (at least that is my experience; any > clue > on how to improve that?). Check with Aaron Reichow - the Squeak-on-PDAs-expert. :) regards, Göran
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: question on differences between images, Edgar J. De Cleene |
|---|---|
| Next by Date: | newbie stuff, David Urquhart |
| Previous by Thread: | Re: question on differences between images, Edgar J. De Cleene |
| Next by Thread: | Re: question on differences between images, Klaus D. Witzel |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |