archives

Janus: A Time-Reversible Language

By C. Lutz and H. Derby circa 1982. Header:

JANUS was written by myself and Howard Derby for a class at Caltech in 1982 (or thereabouts). The class had nothing to do directly with this project. We did it out of curiosity over whether such an odd animal as this was possible, and because we were interested in knowing where we put information when we programmed. JANUS forced us to pay attention to where our bits went since none could be thrown away.

This is class report but also a great design exercise in reversible programming language constructs. For example, I love how they make if conditions reversible:

if   num # 1
then i += 1        ; Put last prime away, if not done
     fact[i] : num ; and zero num
else num -= 1
fi fact[i] # fact[i-1]

Note that # means not equals; colon is used for swap (!!). The "fi" condition must match the truth value of the "if" condition so the condition can be played backwards. Loop constructs are similarly organized so they can play backwards, the language has procedures but all variables are global :).

Sadly, although there are a few follow on papers (e.g. by Yokoyama et al.) and some esoteric reversible languages like Kayak, there doesn't seem to be any other good examples of high-level serious reversible programming languages.

Nimrod: A new statically typed, compiled programming language which supports metaprogramming

Nimrod is a statically typed, imperative programming language that tries to give the programmer ultimate power without compromises on runtime efficiency. This means it focuses on compile-time mechanisms in all their various forms.

Beneath a nice infix/indentation based syntax with a powerful (AST based, hygienic) macro system lies a semantic model that supports a soft realtime GC on thread local heaps. Asynchronous message passing is used between threads, so no "stop the world" mechanism is necessary. An unsafe shared memory heap is also provided for the increased efficiency that results from that model.

I would like to share this language here as it has recently had a new version released. Nimrod resembles Python in that it uses whitespace to delimit blocks and Pascal because of the way that types are defined (TType). It supports metaprogramming with macros and templates. Code example:

# compute average line length
var count = 0
var sum = 0

for line in stdin.lines:
  count += 1
  sum += line.len

echo "Average line length: ",
  if count > 0: sum / count else: 0