Angel \”Java\” Lopez on Blog

December 26, 2012

AjTalk in C# (3) Environments

Filed under: AjTalk, C Sharp, Open Source Projects, Programming Languages, Smalltalk — ajlopez @ 4:46 pm

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:

https://github.com/ajlopez/AjTalk/blob/master/Src/AjTalk.Tests/AssertTests/EnvironmentTests.st

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
    instanceVariableNames:''
    classVariableNames:''
    poolDictionaries:''
    category:''
.

[(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

http://www.ajlopez.com

http://twitter.com/ajlopez

2 Comments »

  1. [...] Previous Post Next Post [...]

    Pingback by AjTalk In C# (2): A Simple Web Server « Angel ”Java” Lopez on Blog — December 26, 2012 @ 4:50 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Shocking Blue Green Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 68 other followers

%d bloggers like this: