Where are system globals (Smalltalk and SystemOrganisation)

Stow, Edward EStow at csu.edu.au
Thu Dec 9 05:00:39 UTC 2004


> The main problem I seem to have with looking at code is seeing what
class
> certain methods are for example in :-

> (Smalltalk reject: [:item | item class isMeta ])
>   associationsDo: [:assoc  | Transcript show: assoc key printString;
cr].

> What class is key, if I look at Association I see key returns a key,
but 
> what class is that key that printString is being applied to ?
> I find this same problem over and over, is there a simple solution ? I
may
> have been given the answer at somepoint but cannot remember.

Even though these one-liners are extremely powerful -- I find that they
are not helpful for newcomers that are still learning Smalltalk syntax.

Having taught smalltalk to u/g students (was it nearly a decade ago !!!)
I found comphrehsion is increased if code is rewritten as below - using
intention revealing local variables and avoiding cascaded messages.

| globalObjects keyPrintString |

globalObjects := Smalltalk reject: [:item | item class isMeta ].
globalObjects  associationsDo: 
	[:assoc  | 
	 assoc halt.
	 keyPrintString := assoc key printString.
	 Transcript show: keyPrintString.
	 Transcript cr]

Then once you can read this code it should be easier to see that 'key'
is a message sent to 'assoc' variable.  So the OP question can be
rephrased as what class defines the method #key.

Two ways that I use. Smalltalk is a dynamic system so make sure you
learn how to use the tools that browse the running system.  The first
tool -- the most important?-- is the debugger.

Try sending halt to the assoc variable.  Open the debugger.  
(Many newcomers find that stepping through loops using the debugger is
confusing -- so I have added the halt inside the block.)
What sort of object is reference by assoc?
Inspect the assoc variable listed in the lower panes of the
debugger.(Right click assoc)

Or second way -- using the Tools flap open drag out a Message Names
browser. Enter key.  Scroll down to the list until you find just 'key'.
Open the browser on the classes that implement key.



--
Edward Stow





More information about the Squeak-dev mailing list