1.4.2 • Published 6 years ago

scheme2js v1.4.2

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

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.

1.4.2

6 years ago

1.4.1

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago