Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
start of scheme in sweet.js (modified from http://pastebin.com/0nPBg8LY)
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")))
}
@simon-o-matic

This comment has been minimized.

Show comment
Hide comment
@simon-o-matic

simon-o-matic Jan 15, 2014

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!

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!

@marcioAlmada

This comment has been minimized.

Show comment
Hide comment
@marcioAlmada

marcioAlmada Aug 17, 2015

these macros doesn't work anymore :(

these macros doesn't work anymore :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment