Daily Archives: December 26, 2012

AjTalk in C# (3) Environments

Previous Post
Next Post

Some weeks ago, I added environments to my open source AjTalk Smalltalk Virtual Machine, C# version. What is an environment, in my jargon? It’s a dictionary for named artifacts, like classes. Smalltalk global is a classical environment. But I want to add support of other named environments, to avoid class name collisions. Usually, classic Smalltalk have pool dictionaries, but I want something more dynamic. Then, I added Environment, see my tests:


At first, Smalltalk is the current environment:

"Current environment is Smalltalk"
[Environment current == Smalltalk] assert.

You can create new environments:

env := Environment new: #MyEnvironment.

Automatically, the new environment is registered/added to the current one, in this case, Smalltalk:

"The new environment was defined as global at Smalltalk"

[(Smalltalk at: #MyEnvironment) isNil not] assert.
[(Smalltalk at: #MyEnvironment) == MyEnvironment] assert.
[(Smalltalk at: #MyEnvironment) == env] assert.

[MyEnvironment isNil not] assert.
[MyEnvironment == env] assert.

Every new Environment has an entry to Smalltalk:

"Dotted expression syntax sugar for MyEnvironment at: #Smalltalk"

[MyEnvironment.Smalltalk == Smalltalk] assert.

You can switch to a new environment:

env setCurrent.

"Current environment check"

[Environment current == env] assert.
[Environment current == Smalltalk.MyEnvironment] assert.

And then, this is the key feature, the class definitions define a new class AT CURRENT environment:

"Define a class at current env environment, no change to syntax"

Object subclass:#MyClass

[(env at: #MyClass) isNil not] assert.
[(Smalltalk at: #MyClass) isNil] assert.

Orthogonally to environments, I implemented modules: a way to search and load file outs, and running them at a new environment (similar to Python import, or (more or less) to Node.js/CommonJS require). But this is a topic for another post 😉

Keep tuned!

Angel “Java” Lopez