Thursday, January 14, 2010

Decrement in Reck

One obvious question about Urbit, of course, is whether you can actually build a practical programming language that uses Nock as an intermediate representation.

Does Watt exist? It does not. It is vaporware. However, I know the problem is solvable, because I've actually built several of these languages. The only one I've actually bootstrapped (that is, used to compile itself to Nock) is the ancient Dogo, which barely had a type system to speak of.

Because any Nock language has to build arithmetic from scratch, the equivalent of "hello, world" is always decrement. Here is decrement in Reck, the predecessor to Watt:
=.  a=@
  =.  b=0
    ?:  (eq a (inc b))
    $(b (inc b))

(This, of course, assumes a kernel which exports gates named eq and inc. But since equivalent operators are built into Nock, these are trivial.)

Reck (like Watt) can be seen as a Lisp dialect, if you can still call something a Lisp dialect when it has (a) a static subject rather than a dynamic environment, and (b) algebraic, higher-order type inference. The syntax is also quite a bit different, as you see. Watt is a lot like Reck, except that all the details are different. (Also, the type system is not as broken.)

If you care to see some more Reck code, you can download a working Reck kernel, through arithmetic and container types, from Google Code. To bootstrap the language, the next stages would be a parser and a Reck-to-Nock compiler. Unfortunately, the Reck type system turned out to need a major overhaul, so...

No comments: