Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!munnari.oz.au!goanna!pnm From: pnm@goanna.cs.rmit.oz.au (Paul Menon) Newsgroups: comp.lang.smalltalk Subject: PP Smalltalk R4 Query, Bug? Keywords: help Message-ID: <4931@goanna.cs.rmit.oz.au> Date: 8 Mar 91 10:50:15 GMT Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 85 hi, I am using Objectworks\Smalltalk Release 4 (what a mouthful) on a Mac and came up against an entry in the User's Guide which makes me worry.. I wasn't getting very good behaviour with certain pieces of code I wrote, so I went back to basics. Pages 30-31 (Messages in sequence) make mention of two ways of doing things, one more efficient ("reduces the wordiness of the code, though often at the expense of readability" - that's not all!). One way: | aDictionary anAssociation | aDictionary := Dictionary new. anAssociation := #Three->3. aDictionary add: anAssociation. The other (more efficient?) way: | aDictionary | aDictionary := Dictionary new add: #Three->3. The second way definitely reduces verbiage, but produces an Association, not a Dictionary!!! I've looked up the appendix on implementation limits and there are some cases which we are warned of, but not this. Even if it were there, why present it in the User Guide as an example? On experimenting, I noticed a way around: | aDictionary | (aDictionary := Dictionary new) add:#Three->3. This produces the right result. I determined this by debugging and examining the compiled code. The 'source' and 'destination' are shown as a summary below. | aDict bDict cDict dDict anAssociation | anAssociation := #Three ->3. aDict := Dictionary new add: anAssociation. [1] bDict := Dictionary new. [2] bDict add: anAssociation. [2] (cDict := Dictionary new) add: (#Three->3). [3] dDict := (Dictionary new) add:#Three->3. [4] The resulting compiled code is below (note the way in which the two bDict statements are handled - ie, correctly, but compressed into one line). Note also how it treats that and the previous statement [1] in two different ways (even with t5 explicitly as #Three->3, ie I tried it both ways). | t1 t2 t3 t4 t5 | t5 := #Three -> 3. t1 := Dictionary new add: t5. (t2 := Dictionary new) add: t5. (t3 := Dictionary new) add: #Three -> 3. t4 := Dictionary new add: #Three -> 3. Of the above, only t2 (bDict, or statement(s) [2]) and t3 (cDict, or [3]) produce the required Dictionary, the others are Associations. What's the score? Is this.. * A bug? * A feature? * Something which disappears when not in 'interactive' mode? * A (:=, new, add:) binding which was not anticipated? * My imagination? If anyone can replicate this, my brain would appreciate it %:-> I'd also appreciate any feedback from ParcPlace. (apologies if this has already been discussed) Thanks, Paul Menon, Dept of Computer Science, Royal Melbourne Institute of Technology, 124 Latrobe Street, Melbourne 3001, Victoria, Australia. pnm@goanna.cs.rmit.oz.au PH: +61 3 660 3209