Of late, I have been having some very little time to kill. But I was pointed to the Cw (pronounced C-omega - and the w is actually written like the omega symbol) - a project running in MSR for quite some time.
I was first fascinated by reading Programming with Circles, Triangles and Rectangles by Erik Meijer and Wolfram Schulte - the main persons behind the Cw project. This paper introduced some very neat concepts and talked about bringing native support of XML to languages like C#, VB or Java.
Many years later, they have a compiler preview for download at the official Cw website.
I downloaded the compiler preview and installed the same. Here is a small preview of the amazing wonders of Cw.
Installation
The installation requirements say Visual Studio .NET 2003, but I guess it would install fine all the same. The installation does add some VS.NET components - now giving a new project type when you start a new project. I sure hope it just ignores this step if it does not find VS.NET installed and does not insist on VS.NET as a compulsory pre-requisite.
Environment
After installation, Cw creates a programs folder accessible from the Start menu. This contains the links to projects of a few samples, a link to the Cw command prompt and a link to the documentation CHM file.
The Comega command prompt is much like the .NET Command prompt. The compiler is cwc.exe and it initiates by calling comegaVars.bat - which sets up some environment variables.
The contents of the comegaVars.bat:
call "D:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\..\Tools\vsvars32.bat"set COMEGAINSTALLDIR=d:\program files\microsoft research\comegaset PATH=d:\program files\microsoft research\comega\bin;%PATH%
As you see, it calls the vsvars32.bat from the .NET 2003 installation path. No doubt this file is written during the installation process. May possibly be one of the reasons it insists on VS.NET 2003 being around, though this could have very well been run from the SDK installation.
Understanding Comega
Comega is a slightly hard-to-understand language when you first look at it. It breaks the notions of the typical C# programmer and has some amazing syntactical structures that leave you wondering what happened to good old C#. However, when you get used to it and begin to understand how it works, things start getting very exciting and very simple.
You actually start wondering how small concepts and little things can be used for constructing rich programming constructs with all the powers of functional programming. Comega actually attempts to bring to the table a lot of interesting experimental concepts.
Sample Comega Program
To show you the powers of Comega, here are a few sample programs (that come bundled with the compiler preview):
Here is a sample called main.cw in the Streams project:
using
public
}
Console.ReadLine();
OneToTen.{ Console.WriteLine(
ns.{ Console.WriteLine(
The above program may look very confusing at first. Here is a simple explanation:
The program relies on the concept of something called Streams. Streams are the basis of how Cw works with iteration. Streams are homogenous collections of a particular type, just like arrays.
However, unlike arrays, streams are lazy evaluated. This means that if an array were to have been assigned to a series of 100 numbers in the FromTo function above, the entire array would be loaded and now ready for use. However, in this sample, the OneToTen variable is just a pointer to a stream *exposed* by the FromTo function. Hence, OneToTen is iterated to get the next value, the FromTo function is still holding a reference previous value of i and a new value (i incremented by 1) is added to the stream.
This concept is well understood by programmers of functional languages like Ruby, Python or Haskell as iterators. From a functional point, iterators and streams behave similarily.
As one might expect, the output of the above program would be:
1 2 3 4 5 6 7 8 9 10
This is quite exciting by itself and might seem like no big deal to many functional programmers. But Comega does not stop here.
Other Comega Features
Comega has a wonderful set of concepts which I will post more about in my future entries. For the moment, it is worth taking a look at the Comega design principles:
The design of Cω is based on three principles: Asynchronous concurrency and processing of relational and semistructured data are sufficiently important that they should be directly supported in a modern general purpose programming language. The advantages of direct linguistic support include: Stronger compile-time guarantees. Intentions and invariants are more apparent in the code. They become part of the interface rather than being buried in the dynamic flow of control into mysterious library routines. The compiler has more information and so has the freedom to choose different implementation strategies (e.g. performing query optimizations). More natural syntax. Better support from other tools such as editors and debuggers. We should extend an already-popular language, rather than design a new one from scratch. The extensions should be principled. The aim is to take models and lessons learnt from the design of more academic, special purpose languages and try to incorporate them within the mainstream object-oriented framework. In the case of concurrency, we took ideas from a theoretical model called the join calculus and a join-based concurrent functional language called JoCaml. In the case of our data extensions, many of the underlying ideas come from functional programming.
The design of Cω is based on three principles:
Exciting new things! Watch this space for more..
Remember Me
Page rendered at Friday, November 21, 2008 4:42:18 AM (India Standard Time, UTC+05:30)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent the views of Microsoft Corporation in anyway.