Well, I’ve gone and done it again—written a language when nobody asked me to. This one might be interesting to game developers, and I’m interested to hear feedback from anyone with an opinion about what ought to be done with it.
The language is called Hap and is designed as a readable dynamic language for game prototyping. It uses single-threaded cooperative multitasking to support simple event-based concurrency. The example from the README sums it up nicely:
var health = 100;
when (health <= 0) {
print("Goodbye, cruel world!");
exit;
}
print("Hello, sweet world!");
while (true)
health = health - 1;
This code prints:
Hello, sweet world!
Goodbye, cruel world!
Hopefully that’s enough to get your attention. Another example shows how you can use the asynchronous control flow statements to write surprisingly readable code:
fun make_cycler(start, end) {
var current = start;
whenever (current > end)
current = start;
ret lam() {
var previous = current;
current = current + 1;
ret previous;
};
}
This function returns a function generating a cycle of values in the given range. For instance:
make_cycler(0, 2)
Will produce the sequence:
0, 1, 2, 0, 1, 2, …
Hap can be used on its own, but the idea is to support embedding in larger systems, much like Lua or JavaScript. Being only a few weeks old, the language naturally has some issues that would need to be addressed before it could be used in production. In particular:
- There is no standard library, and thus no way to perform a number of common math and container operations.
- Embedding the language is not as simple as it should be.
- Asynchronous control flow is not first-class, i.e., there is no way to refer to or halt a “whenever” statement.
- The prototype interpreter is not designed with performance in mind.
I will gladly address these and any other issues if there is interest in the general concept. Tell me what you think!