Skip to content

Instantly share code, notes, and snippets.

@vendethiel
Forked from disnet/scheme.sjs
Last active January 2, 2016 01:29
Show Gist options
  • Save vendethiel/8230315 to your computer and use it in GitHub Desktop.
Save vendethiel/8230315 to your computer and use it in GitHub Desktop.
scheme.sjs (forked from https://gist.github.com/disnet/3854258)
macro sexp {
rule {()} => {
;
}
rule {($p)} => {
$p
}
rule {($x $y)} => {
$x($y);
}
rule {(return $x)} => {
return $x;
}
rule {(display $params)} => {
console.log($params);
}
rule {(define $name $body)} => {
var $name = scheme { $body }
}
rule {(lambda $params $body)} => {
function $params { scheme {$body}}
}
}
macro scheme {
rule { { $x } } => {
sexp $x
}
rule { { $x $rest ... } } => {
sexp $x
scheme { $rest ... }
}
}
scheme {
(display "hello")
(display "foo")
(define foo (lambda (a) (return "hello")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment