Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rkrupinski/clojure-lite
Compiles an extremely small subset of clojure to JavaScript
https://github.com/rkrupinski/clojure-lite
Last synced: about 1 month ago
JSON representation
Compiles an extremely small subset of clojure to JavaScript
- Host: GitHub
- URL: https://github.com/rkrupinski/clojure-lite
- Owner: rkrupinski
- Created: 2016-12-22T19:02:49.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-22T19:06:55.000Z (about 8 years ago)
- Last Synced: 2024-10-13T18:57:57.027Z (2 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# clojure-lite
*Disclaimer: this is a super-immature toy project :bowtie:*
`clojure-lite` compiles an extremely small subset of [clojure](https://clojure.org/) to JavaScript. That's pretty much all it does. Have fun!
It currently lets you:
- define and refer variables
- define and call functionsOther quirks:
- the standard library is limited to `+`, `-`, `*`, and `/`
- there's only one type: `number`## Example
```clojure
(def PI 3.141592653589793)
(defn area [radius] (* PI radius radius))
(area 5)
```
is compiled to:
```javascript
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:```sh
$ npm install clojure-lite --save
```
```javascript
const cl = require('clojure-lite');const compile = _.compose(
cl.codegen,
cl.parser,
cl.lexer
);const code = compile('(def answer 42)');
```CLI:
```sh
$ npm install -g clojure-lite
```
```sh
$ echo '(def answer 42)' | cl > code.js
```## Credits
- `lexer` heavily inspired by [[click]](https://www.codeproject.com/articles/345888/how-to-write-a-simple-interpreter-in-javascript).
- `parser` & `codegen` heavily inspired by [[click]](https://github.com/thejameskyle/the-super-tiny-compiler).