A Lisp to Javascript compiler
Switch branches/tags
Pull request Compare This branch is 5 commits behind honza:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
inertia
.gitignore
LICENSE
Makefile
README.md
inertiac
package.json

README.md

inertia

A LISP to Javascript compiler.

work in progress

a learning exercise

Read the accompanying blog post.

How it works

It uses PEG.js to parse the source to a Parser API compatible AST. The AST is then transformed to Javascript via escodegen.

It can optionally compress the output via Uglify.

Example

Source:

(def name "honza")

(def greet
  (fn [name]
    (console.log "hey" name)))

(greet name)

Output:

var name = 'honza';
var greet = function (name) {
    return console.log('hey', name);
};
greet(name);

Usage

Usage: inertia [options] <file...>

Options:

    -h, --help           output usage information
    -V, --version        output the version number
    -t, --ast            Print the AST
    -o, --output [file]  Redirect output to file
    -c, --compress       Minify with uglify

You can use the Makefile to install the dependencies:

$ make install

Or to build the compiler:

$ make

Or to build all the examples:

$ make example

What works

  • def
  • list
  • +, -, *, /, =, !=, <, >, <=, >=
  • if
  • (fn [] ...)
  • {}, {"name" "honza"}
  • comments ;;
  • let

Standard library

  • nth
  • first
  • rest
  • second
  • last
  • partition
  • cons
  • conj
  • get
  • map
  • filter
  • update (update a key in a map (update obj key value)

Note: The standard library functions are modelled after Clojure.

TODO

  • Macro support

License

BSD, short and sweet

Feedback

All feedback is most welcome. Open an issue for any purpose.