BAM Weblog

Roy - Meta-programming and a REPL

Brian McKenna2011-07-03

Roy now has a limited, compile-time meta-programming system. Simple example:

macro printArgLength =
  console.log "Compiling to:" arguments.length
  [| console.log &(arguments.length) |]

printArgLength 1
printArgLength 1 2
printArgLength 1 2 3

The code above will output messages during compilation. This is the JavaScript output:

console.log(1)
console.log(2)
console.log(3)

I'd really like to make Roy's meta-programming work more like Template Haskell or Converge. Unfortunately I have only skimmed papers on both and used neither. My goal is to make the meta-programming powerful enough to express modules and do notation.

I also built a REPL for Roy in about 20 minutes. Amazing how simple it is to create a nice REPL in node.js by using the readline module.

$ ./roy
roy> 10 * 2 - 5
15 : Number
roy> 
Please enable JavaScript to view the comments powered by Disqus.