-
-
Save vendethiel/8230315 to your computer and use it in GitHub Desktop.
scheme.sjs (forked from https://gist.github.com/disnet/3854258)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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