0.0.1 • Published 7 years ago

clojure-lite v0.0.1

Weekly downloads
6
License
-
Repository
github
Last release
7 years ago

clojure-lite

Disclaimer: this is a super-immature toy project :bowtie:

clojure-lite compiles an extremely small subset of clojure to JavaScript. That's pretty much all it does. Have fun!

It currently lets you:

  • define and refer variables
  • define and call functions

Other quirks:

  • the standard library is limited to +, -, *, and /
  • there's only one type: number

Example

(def PI 3.141592653589793)
(defn area [radius] (* PI radius radius))
(area 5)

is compiled to:

const __lib = {};
__lib['*'] = function (...args) {
  return args.reduce((acc, curr) => acc * curr, 1);
};
let PI = 3.141592653589793;
function area(radius) {
  return __lib['*'](PI, radius, radius);
}
area(5);

Usage

Programmatic:

$ npm install clojure-lite --save
const cl = require('clojure-lite');

const compile = _.compose(
  cl.codegen,
  cl.parser,
  cl.lexer
);

const code = compile('(def answer 42)');

CLI:

$ npm install -g clojure-lite
$ echo '(def answer 42)' | cl > code.js

Credits

  • lexer heavily inspired by [click].
  • parser & codegen heavily inspired by [click].