Scripting with MAGES

The first version of MAGES is about to be released.

In the recent weeks I spent a bit of time on developing MAGES. It seems that in roughly two weeks I am able to release v1, the first finished version of the library.

MAGES is a scripting library that enhances .NET by making it possible to glue existing code with a very dynamic scripting layer. It is different to the Iron languages and other MSIL-based languages as it is interpreted within the .NET runtime. It only requires .NET 3.5 and can be used together with Unity. The interpretation model makes it suitable to be deployed within an iOS application.

On the library's side one of the main features was performance. While YAMP was a successful experiment, it lacked some of the features that are now baked into MAGES. MAGES is faster out-of-the-box, but by using features such as one-time validation (i.e., cached executed) it outperforms YAMP easily beyond a full magnitude. Furthermore, as MAGES uses .NET data-types, matrix operations are faster by definition. This yields a speedup that scales, e.g., for N^3 in multiplications the speedup results in a huge difference for larger matrices.

Besides the obvious performance and convenience features MAGES comes with trivial possibilities of including .NET code. Essentially, there is no wrapper required. MAGES handles this just without requiring much ceremony. In the end it is quite a pleasure to take existing .NET code and expose it within MAGES.

Finally, the language also comes with some nifty features. Even though the language itself was never considered to be revolutionary, it is still practical for many applications. Yes, the key focus is on mathematical expressions, however, in contrast to YAMP normal objects are included out-of-the-box. Besides MAGES's object literals (new { }), there are function literals ((x, y, z) => x + y + z) and matrix literals ([1,2;3,4]).

MAGES introduces the pipe-operator, which takes any value on the left and passes it to the function on the right, i.e., x | sin == sin(x). This is especially useful with currying, which is an integrated feature. If any function is invoked with less arguments than required, then a (potentially captured) version of the function is returned. Therefore, add(2)(3) = add(2, 3) or is_string = is("String"). The latter describes how a useful helper is created to avoid calling is("String", x), but just is_string(x). Together with the pipe-operator we obtain the flexibility to write, e.g., x | add(3) | subtract(y) | multiply(z) | factorial.

Version 1 will contain some other nice features, but the library itself will stay lightweight and focused.

Created .

References

Sharing is caring!