BAM Weblog

Roy

Brian McKenna — 2011-05-29

This week I’m releasing a toy functional language that compiles to JavaScript. I’ve named it “Roy” and you can find it on Bitbucket. It’s just over 1000 lines of JavaScript.

It uses my past two projects from projectaweek:

Here’s an example of the language:

let gcd a b =
  if b == 0 then
    a
  else
    gcd b (a % b)

console.log (gcd 49 35)

And here’s the (ugly) JavaScript output:

"use strict";
var gcd = function(a, b) {return (function(){if(b == 0){return a}else{return gcd(b, a % b)}})();;};
console.log(gcd(49, 35))

Roy will serve as the basis for a new language I’m working on. The next language will:

  • Improve JavaScript interop
  • Structural typing
  • Tail recursion
  • Algebraic data types
  • Pattern matching
  • Prettify the JavaScript output
Please enable JavaScript to view the comments powered by Disqus.