<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On 25.08.2009, at 23:52, r00t uk wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Bert - I don't think creating a Squeak version of that would have helped anybody new to squeak/smalltalk.</blockquote><div><br></div><div>Right, in this case not, but that's not what I meant primarily. Should have changed the subject and moved to squeak-dev, sorry. I'll make up for it, see below&nbsp;[*].</div><div><br></div><div>I meant that I've never seen a graphical explanation of what Randal did in these "few minutes" to find out. It's what experienced Smalltalkers do all the time, and Squeak provides powerful ways of finding out about itself, but they are not obvious to newbies.</div><div><br></div><div>Usually we don't even mention that it took us a minute to find out, so beginners get the impression that it's "all in our heads". It's not (not *all* anyway) but the tools allow us to find out quickly. Faster than looking up documentation indeed, which we can't really proof because of the lack of it ;)</div><div><br></div><blockquote type="cite">&nbsp; Cookbook wiki maybe?<br><br><br><div class="gmail_quote">2009/8/25 Bert Freudenberg <span dir="ltr">&lt;<a href="mailto:bert@freudenbergs.de">bert@freudenbergs.de</a>&gt;</span><br> <blockquote class="gmail_quote" style="border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); margin-top: 0pt; margin-right: 0pt; margin-bottom: 0pt; margin-left: 0.8ex; padding-left: 1ex; position: static; z-index: auto; "><div class="im"><br> On 25.08.2009, at 23:31, Randal L. Schwartz wrote:<br> <br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> There might be a far better way.. but I found this in a few minutes.<br> </blockquote> <br> <br></div> Someone should make a Squeak version of<br> <br> &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://xkcd.com/627/" target="_blank">http://xkcd.com/627/</a><br> <br> - Bert -<br><br></blockquote></div></blockquote></div><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Lucida Grande; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><div style="font-family: Helvetica; "><font class="Apple-style-span" face="'Lucida Grande'"><span class="Apple-style-span" style="font-size: medium;"><font class="Apple-style-span" face="Helvetica"><font class="Apple-style-span" face="'Lucida Grande'"><font class="Apple-style-span" face="Helvetica"><br></font></font></font></span></font></div><div style="font-family: Helvetica; "><span class="Apple-style-span" style="font-size: medium;"><br></span></div><div style="font-family: Helvetica; "><span class="Apple-style-span" style="font-size: medium;">[*] Here's what I'd do:</span></div><div style="font-family: Helvetica; "><span class="Apple-style-span" style="font-size: medium;"><br></span></div><div style="font-family: Helvetica; "><span class="Apple-style-span" style="font-size: medium;">Make a little test case in a workspace:</span></div><div style="font-family: Helvetica; "><span class="Apple-style-span" style="font-size: medium;"><br></span></div><div style="font-family: Helvetica; "><span class="Apple-style-span" style="font-size: medium;">| dict |</span></div><div style="font-family: Helvetica; "><span class="Apple-style-span" style="font-size: medium;"><div>dict := {'a' -&gt; 'first'. 'b' -&gt; 'second'. 'c' -&gt;'third'} as: Dictionary.</div><div>dict&nbsp;</div><div><br></div><div>This intentionally does not use integers as keys, because that's what's special about Dictionaries. (and in fact I didn't really open a workspace but typed it right in the browser I happened to have open. Saves a second)</div><div><br></div><div>When I printed the expression above, the elements *were* sorted by key. So this may be chance, but I wanted to see. So I double-clicked Dictionary, pressed cmd-b to bring up a browser, clicked in the right pane with all the methods, and pressed p, to find printing-related methods (I should have clicked the "printing" protocol but usually methods are named more sanely than they are categorized). Anyway this took me right to the "printElementsOn: aStream" which indeed sorts. That could be a template for your own solution.</div><div><br></div><div>But in any case the print string of the dictionary is not helpful to show the problem. So:</div><div><br></div><div><span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 12px; "><div style="font-family: Helvetica; "><span class="Apple-style-span" style="font-size: medium; ">| dict |</span></div><div style="font-family: Helvetica; "><span class="Apple-style-span" style="font-size: medium; "></span></div></span><div>dict := {'a' -&gt; 'first'. 'b' -&gt; 'second'. 'c' -&gt;'third'} as: Dictionary.</div><div>dict asArray</div><div><br></div><div>Yes, this printed #('second' 'third' 'first'), so now we need to sort. I have the idiom in my head but I typed in in anyway to verify</div><div><br></div><div><div>| dict &nbsp;|</div><div>dict := {'a' -&gt; 'first'. 'b' -&gt; 'second'. 'c' -&gt;'third'} as: Dictionary.</div><div>dict keys asSortedCollection collect: [:key | dict at: key]</div><div><br></div><div>And this indeed gives&nbsp;&nbsp;an OrderedCollection('first' 'second' 'third')</div><div><br></div><div>So if I had sent an answer to your question I probably would have just pasted the line</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>dict keys asSortedCollection collect: [:key | dict at: key]</div><div><br></div><div>not even mentioning that it took me a minute to verify, and that en passant I discovered that dictionary printing is sorted for a couple of years already, which I had not noticed ;)</div><div><br></div><div>Comparing this to Randal's suggestion I'd say that mine feels more "Smalltalky". Accessing the associations in a dictionary directly feels unclean. Maybe because it breaks the abstraction, associations are an implementation detail of dictionaries. It's unlikely this will ever change and accessing the associations is fine, but still ;)</div><div><br></div><div>- Bert -</div></div></div></span></div></div></span></div></body></html>