Squeak and Namespaces
james at foster.net
Thu Nov 30 05:58:49 UTC 2006
In GemStone/Smalltalk rather than having a single SymbolDictionary
(Smalltalk) that contains all the globals, there is a list of
SymbolDictionary instances each of which is examined to see if it has the
key being referenced. There is no built-in support for nesting-just an Array
of SymbolDictionary instances instead of a single SymbolDictionary instance.
myTest := TestCase new.
Is equivalent to:
myTest := (System myUserProfile symboList resolveSymbol:
#'TestCase') value new.
By convention, each SymbolDictionary instance is contained in itself as a
value where the key is its "name." For example, filing in the SUnit package
results in creation of a new SymbolDictionary whose initial key is #'SUnit'
with the new SymbolDictionary instance as its value. The new
SymbolDictionary instance is added as the first entry in the current
SymbolList instance (so that any other globals with identical names are
effectively hidden), and then the file-in proceeds adding various keys
including #'TestCase', #'TestResource', #'TestResult', and #'TestSuite'
(each of which has an associated value that is the named class).
If I wanted to be more particular about the lookup in the above code
example, I could specify:
myTest := (SUnit at: #'TestCase') new.
Or, to be more specific:
myTest := ((System myUserProfile symboList at: 2) at:
Or, to be more specific still:
myTest := (((AllUsers userWithId: 'JamesFoster') symbolList at:
2) at: #'TestCase') new.
Importantly, there is no change in the language syntax. The "magic" happens
during method compilation where one of the arguments to the compiler is the
SymbolList instance that is to be searched for any needed global references.
Different methods can be compiled with reference to different SymbolList
instances, and still call each other. This allows for private classes, class
replacement, etc. It has served reasonably well for a couple decades.
From: Michael van der Gulik [mailto:mikevdg at gmail.com]
Sent: Wednesday, November 29, 2006 8:52 PM
To: james at foster.net; The general-purpose Squeak developers list
Subject: Re: Squeak and Namespaces
On 11/30/06, James Foster <james at foster.net> wrote:
Michael's description is something like what GemStone/Smalltalk
provides-each login is assigned an array of SymbolDictionary instances (a
SymbolList), and compiling is in the context of a SymbolList. You can have
multiple globals visible with the same name, but the first one found is
used. Different code can be compiled with different instances of SymbolList,
and multiple instances of SymbolList can reference the same
SymbolDictionary. Security can be addressed by giving a user a SymbolList
that does not reference things that should be hidden.
That sounds interesting.
- How do you specify that. rather than the first global found, you want to
use a different global with the same name?
- Can SymbolDictionaries be nested? I.e.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev