scheme2js

1.4.2 • Public • Published

scheme2js

Compiler for transpiling Scheme to JavaScript

Demo

You can see the live demo here.

Installation

$ npm install scheme2js

CLI

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

API

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 = 1

Function 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 : d

Binary Expressions

Lisp

(+ 1 2)

JavaScript

1 + 2

Boolean 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 --pairs

This will add the required polyfill and define it globally.

/scheme2js/

    Package Sidebar

    Install

    npm i scheme2js

    Weekly Downloads

    0

    Version

    1.4.2

    License

    MIT

    Unpacked Size

    96.7 kB

    Total Files

    117

    Last publish

    Collaborators

    • dongyeop