Unimperative is my latest creation, a Lisp dialect which is entirely functional but also compiles, without changes but with the appropriate library of course, as C++. I will be posting the source code on my web site in about a week, but here is a taste of what is coming up:
The canonical way to demonstrate a functional language is probably to show the factorial function, so without further ado:
Def declares the following token is the name of a function. In Unimperative a list, i.e. anything between two paranthesis, is interpreted as a function to be evaluated followed by arguments to that function. Functions in Unimperative are first class and are not evaluated, unless they are the first member of a list, or they are the first argument following the Eval operator.
There are no variables in Unimperative, apart from function variables. The _1, _2, etc., symbols refer to the arguments to the current function. The self is a special symbol which refers to the current function.
Compiling Unimperative in a C++ operator is made possible by using a library of dynamically typed objects, and by sneakily overloading the comma operator.
What makes Unimperative interesting, at least for me, is that it is one of the most portable languages around. It will compile in most any C++ compiler, or can be interpreted wherever an interpreter can be found. This dual nature also makes it very interesting for Agile development, in that testing, refactoring and prototyping can be done in C++ without recompiling, and when the version is stable, the code can be committed to the executable.
For those like me who just can't get enough of sample code, here is my current test suite for both the interepreter and as embedded C++ code:
That's awesome! I would love to see the source code behind that. I'm going to guess that it is dynamically typed? If so, would it be possible to make it statically typed and what impact would that have on the clean syntax? I only ask because, if one wants to be able to compile it with a C++ compiler, that might mean there is a performance concern. Of course, perhaps the biggest advantage is the portability of C++.
I am actually working on a similar project right now. But rather than a functional sub-language, I am aiming at a Java-like C++ sub-language supporting reflection and automatic memory management. The idea is to get some of the advantages of Java on a platform (video games console) without a JVM. See the link in my profile if you're interested.
>I would love to see the source code behind > that.
In a week or two (possibly more) it should be posted all at http://www.ootl.org .
> I'm going to guess that it is dynamically typed?
Yes, I currently use boost::any but I will soon be switching to an updated version of the ootl::object class.
> If > so, would it be possible to make it statically typed and > what impact would that have on the clean syntax?
Yes. A typed version could be trivially implemented as:
Def<int, int> IntAdd = (Add, x, y);
> I only > ask because, if one wants to be able to compile it with a > C++ compiler, that might mean there is a performance > concern.
It is very slow for the time being. Only about 40% faster compiled than interpreted. It is very immature however.
> Of course, perhaps the biggest advantage is the > portability of C++.
That's what I was striving for.
> I am actually working on a similar project right now. But > rather than a functional sub-language, I am aiming at a > Java-like C++ sub-language supporting reflection and > automatic memory management. The idea is to get some of > the advantages of Java on a platform (video games console) > without a JVM. See the link in my profile if you're > interested.
> That's awesome! I would love to see the source code behind > that. I'm going to guess that it is dynamically typed? If > so, would it be possible to make it statically typed and > what impact would that have on the clean syntax?
I thought you might be interested to know that Unimperative has been rejuvenated at http://www.unimperative.com as a typed concatenative language.