public
Last active

start of scheme in sweet.js (modified from http://pastebin.com/0nPBg8LY)

  • Download Gist
scheme.sjs
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
macro sexp {
case () => {
;
}
case ($p) => {
$p
}
case ($x $y) => {
$x($y);
}
case (return $x) => {
return $x;
}
case (display $params) => {
console.log($params);
}
case (define $name $body) => {
var $name = scheme { $body }
}
case (lambda $params $body) => {
function $params { scheme {$body}}
}
}
 
macro scheme {
case { $x } => {
sexp $x
}
case { $x $rest ... } => {
sexp $x
scheme { $rest ... }
}
}
 
scheme {
(display "hello")
(display "foo")
(define foo (lambda (a) (return "hello")))
}

Wow. This blew me away. These type of macros are are rushing back to me now from my scheme days and to know I can now have them in my new favourite language, JavaScript, is such a joy. And presenting it as a scheme macro that creates scheme in JavaScript in 33 lines of code, to boot!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.