Compiler for transpiling Scheme to JavaScript
You can see the live demo here.
$ npm install scheme2js
Compile the file script.scm
and output it to stdout.
$ s2j script.scm
Compile the file script.scm
and output it to script.js
$ s2j script.scm -o script.js
const s2j = require('scheme2js')
const code = '(+ 1 2)'
const result = s2j(code) // '1 + 2'
Lisp
(add 1 2)
JavaScript
add(1, 2)
Lisp
(define foo 1)
JavaScript
var foo = 1
Lisp
(define (plusOne x) (+ x 1))
JavaScript
function plusOne(x) {
return x + 1
}
Lisp
(define (addOne x)
(define (add y) (+ x y))
(add 1))
JavaScript
function addOne(x) {
function add(y) {
return x + y
}
return add(1)
}
Lisp
(if
(eq a b)
c
d)
JavaScript
eq(a, b) ? c : d
Lisp
(+ 1 2)
JavaScript
1 + 2
Lisp
(and (x > 5) (x < 10))
JavaScript
(x > 5) && (x < 10)
Lisp
(lambda (x y) (+ x y))
JavaScript
function(x, y) {
return x + y
}
To add support for cons
, car
, cdr
procedures, specify the --pairs
or -p
option.
$ s2j script.scm --pairs
This will add the required polyfill and define it globally.