The State of CommaScript, January 2014 edition

Ever since I first announced CommaScript back in August of 2013, I've been working on getting the first implementation finished. It's a reasonably large project, so I'm not done yet, but I am making progress. Most of the syntax has been defined, and about two thirds of the analyzer is implemented.

Primitives are the furthest ahead since they form the building blocks of everything else. As it turns out, the syntax is even simpler than I first anticipated: there is no syntax :).

In CommaScript, the var keyword works just like the auto keyword in C++/11 or the var keyword in C# (I think Java recently added something similar, but I haven't been keeping up with Java lately). The key difference, of course, is that there is no typed alternative to var in JavaScript (and thus CommaScript), unlike C++ or C# with int, char, etc.  This means that all var expressions must have a resolvable type on the right hand side in CommaScript.

For primitives, this is actually really simple, since all primitive literals have an inherent type (a string is obviously a string, and obviously not a number, or object, and so on). Primitives also have mechanisms for converting to other primitive types (toString(), toValue(), !!, etc). This means that there isn't any information that needs to be inferred that isn't already there in JavaScript syntax.

Most of the implementation behind primitives is finished as well. The only thing missing is a few expressions (mostly unary expressions). This means that all sorts of expressions are possible today. The following parses correctly:

'use commascript';

var foo = true;  
foo = false;  

as does:

'use commascript';

var w = 0,  
    x = true,
    y = 10,
    z = 20;

w = x ? y : z + 20;  

And the following correctly throws an error:

'use commascript';

var x = 0;

x = 10 * 'hello';  

I also have functions fully implemented. Functions cannot be fully inferred, however, so they need to be declared ahead of time. There are two ways to do this: via function expressions or function declarations. Function expressions are more explicit, and a bit easier to read, but also more verbose.

'use commascript';

('define(function,foo)', {});

var foo = ('cast(foo)', function () {});  

The other is a function definition, which shortcuts some of the more explicit nature of function expressions:

'use commascript';

('define(function,foo)', {
  returnType: 'string',
  argumentTypes: ['string', 'number']
});

function foo(a, b) {  
  var x = 'str',
      y = 10;
  x = a;
  y = b;
  return x;
}

Objects are about half way defined. Object literals are supported, but constructors/prototypes are not.

('define(object,foo)', {
  properties: {
    'bar': 'string',
    'baz': 'number'
  }
});

var obj = ('cast(foo)', null);  
obj = {  
  'bar': 'hello world',
  'baz': 10
};
obj.bar = 'goodbye';  
obj.baz = 20;  

Arrays are not supported at all yet.

So that's where CommaScript is at these days. Making progress, but still a ways to go.