Skip to content
/ lispjs Public

Let's compile Lisp into JavaScript using JavaScript

Notifications You must be signed in to change notification settings

jdan/lispjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lispjs

Let's compile Lisp into JavaScript using JavaScript

Check out the unit tests for a good idea of how this works.

See scheme-to-js for a similar effort, written in Scheme.

Usage

$ git clone https://github.com/jdan/lispjs.git
$ cd lispjs
$ npm install
$ cat digits.scm
(define (idiv a b)
    (Math.floor (/ a b)))

(define (digitsHelper q)
    (if (== 0 q)
        []
        (cons (modulo q 10)
              (digitsHelper (idiv q 10)))))

(define (digits n)
    (reverse (digitsHelper n)))

(print (digits 103))
$ node cli.js digits.scm --no-eval
function print() {
    return console.log.apply(console, [].slice.call(arguments))
};function reverse(xs) {
    return xs.slice().reverse()
};function mod(a, b) {
    return a % b
};function cons(x, xs) {
    return [x].concat(xs)
};function eq(a, b) {
    return a === b
};function div() {
    const args = [].slice.call(arguments)
    return args.slice(1).reduce((a, b) => a / b, args[0])
};function idiv(a,b){return Math.floor(div(a,b))};function digitsHelper(q){return (eq(0,q))?([]):(cons(mod(q,10),digitsHelper(idiv(q,10))))};function digits(n){return reverse(digitsHelper(n))};print(digits(103))
$ node cli.js digits.scm
[ 1, 0, 3 ]

Test

$ npm test

About

Let's compile Lisp into JavaScript using JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published