This is a toy programming language implemented using functional javascript. An attemp to learn both both functional JS and Clojure. Implementing a turing complete language in so few lines of code was incredibly fun.
The following 2 files are important:
-
src/parser.js
Take a string written in Lisp and converts to JS data structure.- List enclosed in
()
are converted to JS arrays. - Vectors enclosed in
[]
are converted to JS arrays. - Strings are converted to JS strings.
- Numbers are converted to JS numbers.
- Boolean are convreted to JS boolean.
- Regular expression are converted to JS RegExp.
- Maps enclosed in
{}
are converted to JSMap
, notObject
. - Sets enclosed in
#{}
are converted to JSSet
. - Short Lambdas
#(...)
are converted to JS arrays. - Everything else is an identifier.
- List enclosed in
-
src/evaluator.js
Takes JS data structure of a Lisp program and runs it. It supports lazy evaluation of function arguments, closure, lambda, destructuring and rest arguments, short lambda sytnax. And a handful of core clojure functions like+, -, *, /, =, mod, map, filter, reduce, println, range, count, int, nth
and a few more. Check theexamples/
folder for examples.
NodeJS 4+ is required. Then run the following commands
npm install
chmod a+x src/lipsy
src/lipsy examples/hello.clj
Inspired from SICP, implemented some cool stuff
like lazy evaluation of function arguments and lazy def
. Functions are first
class with support for closure.