1.4.2 • Published 7 years ago
scheme2js v1.4.2
scheme2js
Compiler for transpiling Scheme to JavaScript
Demo
You can see the live demo here.
Installation
$ npm install scheme2jsCLI
Compile the file script.scm and output it to stdout.
$ s2j script.scmCompile the file script.scm and output it to script.js
$ s2j script.scm -o script.jsAPI
const s2j = require('scheme2js')
const code = '(+ 1 2)'
const result = s2j(code) // '1 + 2'Features
Expressions
Lisp
(add 1 2)JavaScript
add(1, 2)Naming
Lisp
(define foo 1)JavaScript
var foo = 1Function Definition
Lisp
(define (plusOne x) (+ x 1))JavaScript
function plusOne(x) {
return x + 1
}Nested Definitions
Lisp
(define (addOne x)
(define (add y) (+ x y))
(add 1))JavaScript
function addOne(x) {
function add(y) {
return x + y
}
return add(1)
}Conditional Expressions
Lisp
(if
(eq a b)
c
d)JavaScript
eq(a, b) ? c : dBinary Expressions
Lisp
(+ 1 2)JavaScript
1 + 2Boolean Expressions
Lisp
(and (x > 5) (x < 10))JavaScript
(x > 5) && (x < 10)Lambda Expressions
Lisp
(lambda (x y) (+ x y))JavaScript
function(x, y) {
return x + y
}Polyfills
Pairs
To add support for cons, car, cdr procedures, specify the --pairs or -p option.
$ s2j script.scm --pairsThis will add the required polyfill and define it globally.