GNU Smalltalk User's Guide
4.2.4 Smalltalk dictionary
If you'll remember from the beginning of the chapter,
we started out by saying:
Smalltalk at: #x put: 0 !
This code should look familiar--the
at:put: message is how
we've been storing information in our own arrays and
dictionaries. In a Smalltalk environment the name
has been preset to point to a dictionary (21) which both you and
Smalltalk can use. To see how this sharing works, we'll
first try to use a variable which Smalltalk doesn't know
Smalltalk complains because
y is an unknown variable.
Using our knowledge of dictionaries, and taking advantage of
our access to Smalltalk's dictionary, we can add it ourselves:
Smalltalk at: #y put: 0 !
The only mystery left is why we're using
#y instead of our
usual quoted string. This is one of those simple questions
whose answer runs surprisingly deep. The quick answer is
'y' are pretty much the same, except
that the former will always be the same object each time you use
it, whereas the latter can be a new string each time you do so.
Now that we've added It works! Because you've added an entry for
y to Smalltalk's dictionary, we
is now perfectly happy to let you use this new variable.
If you have some spare time, you can print out the
entire Smalltalk dictionary with:
As you might suspect, this will print out quite a large list
of names! If you get tired of watching Smalltalk grind it
out, use your interrupt key (control-C, usually) to bring
Smalltalk back to interactive mode.