New Release of Essence#: ‘Golden Rule-1’ (Alpha Build 12)

The Golden Rule-1 release is mostly about fixing bugs and improving the stability and robustness of the system–although it also includes some minor new functionality (see below for two examples.)

The Golden Rule-1 release can be downloaded from the Essence# site on CodePlex (which gets you the installer.) Alternatively, the code for the run time system (written in C#) can be obtained from theEssence# CodePlex site using Git, and the code for the Essence# Standard Library can be obtained from GitHub. And the example scripts can also be downloaded from the new Scripts repository on GitHub.

The release notes on CodePlex provide two examples of some minor new functionality added by this release. Please read the release notes for the details.

In addition to the new functionality, the bug fixes have enabled features that used to work, stopped working at some unknown point in the past, but are now working again. Permit me to demonstrate some of them in the following example script:

| class color |

"Create a new class and assign it to the local variable 'class'"
class := Class new. 

"Configure the new class to have the desired superclass,
name and instance variables, and declare it in the
desired namespace ('environment')."
class
        superclass: Object; 
        name: #Color; 
        instanceVariableNames: #(red green blue); 
        environment: Smalltalk. 

"Add setter and getter methods to the new class"
class   
        addMethod: [## red ^red];
        addMethod: [## red: aPositiveNumber red := aPositiveNumber];
        addMethod: [## green ^green];
        addMethod: [## green: aPositiveNumber green := aPositiveNumber];
        addMethod: [## blue ^blue];
        addMethod: [## blue: aPositiveNumber blue := aPositiveNumber].

"Create an instance of the new class"
color := class new. 

"Use the setter methods defined above to initialize the instance 
variables of the newly-created instance of Color"
color   
        red: 192;
        green: 144;
        blue: 92;
        yourself

The example uses method literal syntax to define methods. Although those have been working ever since the moment the Essence# compiler was able to compile anything at all–and they are used exclusively in the Essence# class library as the syntax for defining methods–there were limitations on their use (partially due to bugs) that have now been eliminated. Specifically, it used to be the case that the containing scope in which they were defined had to be the same class in which they would be installed as methods. That restriction is now lifted.

However, there are consequences to lifting that restriction, one of which is that the compiler will blithely accept and ignore any undeclared variables in a method literal when the syntax demonstrated by the example above is used to express the method literal. Fortunately, there is an extended syntax for method literals that can be used so that the compiler will not ignore and will not accept references to undeclared variables. Here’s an example:

[## Color>>alpha 
        "Answer the value of the instance variable 'alpha'"

        ^alpha
]

If the method literal starts with a class name, followed by a “>>” token (which then must be followed by the method’s selector), then the compiler will compile the method in the context of the named class, using the definition of the class at the time of compilation to resolve variable refernces. And the compiler will then also abort the compilation with an error if any of the variable references cannot be resolved. The class name may optionally use qualified name syntax (“dotted notation”) so as to refer to classes in specific namespaces.

Actually, there is much functionality in Essence# which I have not yet discussed. I will be revealing it as time permits.

Advertisements

One response to “New Release of Essence#: ‘Golden Rule-1’ (Alpha Build 12)

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