cljs-bootstrap
This project uses bootstrapped ClojureScript to implement node.js and web ClojureScript REPLs. The bootstrapped aspect means that the REPLs run using only JavaScirpt files (i.e. without a JVM).
Note: this was originally a fork of https://github.com/swannodette/cljs-bootstrap
This is a work in progress and many things work but there are still bugs (see examples below).
Just the REPL please
If you just want to the bootstrapped ClojureScript REPL, you try the web version at clojurescript.net or you can download a pre-built Node.js version and run it like this:
curl https://gist.githubusercontent.com/kanaka/b588dbb6d44174672cc2/raw/repl-node.js > clojurescript.js
chmod clojurescript.js
./clojurescript.js
Build the REPL
To build the bootstrapped REPL, follow these steps:
- First, check out the repositories:
git clone https://github.com/clojure/clojurescriptgit clone --branch cljs-bootstrap https://github.com/swannodette/tools.readergit clone https://github.com/kanaka/cljs-bootstrap
- Build and install the regular ClojureScript compiler and patched reader:
cd clojurescripttime ./script/build# Note the version of ClojureScript that is built. cd .. cd tools.readerlein installcd ..
- Update the cljs-bootstrap
project.def
with the version of ClojureScript that was built above and then install Node/npm dependencies (source-map-support and readline-sync):
cd cljs-bootstrapvi project.def # update to correct ClojureScript version lein npm install
- Bootstrap build the ClojureScript compiler and simple REPL (this
compiles to JavaScript in the
.cljs_bootstrap/
directory):
time lein run -m clojure.main script/build.clj
- Run the REPL using a Node launch script:
node repl.js
-
Optionally, you can now build/compile the sources into a single standalone JavaScript file
repl-node.js
(as per the gist above).- First you need to download and unzip the Google Closure compiler jar file:
wget http://dl.google.com/closure-compiler/compiler-latest.zip
unzip compiler-latest.zip
- Now generate the standalone all-in-one REPL files for node.js (repl-node.js) and the web (repl-web.js):
./script/gen_single.sh
- Run the standalone all-in-one REPL:
./repl-node.js
Dynamic namespace loading
To load/evaluate arbitrary libraries/namespaces you must first configure the
search path. For example, to load the "joel.core" namespace from
src/joel/core.cljs
, you need to configure the loader like this:
cljs.user> (cljs-bootstrap.repl/set-load-cfg :lib-base-path "src/")
Now you can load it and use it like this:
cljs.user> (ns foo.bar (:require joel.core))
foo.bar> (joel.core/some-fn 1 2 3)
Macros are supported by bootstrapped ClojureScript but they still must live in a separate file from regular ClojureScript code and are loaded using :require-macros.
Examples
- Try some code that works:
.> :foo : .> 123 123 .> 5 .> 3 .> 12 .> 20 .> 20 .> : : : .> #'./x .> #'./ .> 42 .> #'./ .> 56 .> 8 .> .> 84 .> 4 .> .> "hello" .> nil .> "lots of foo" nil .> ./ .> "some bar too" nil .> ./ .> "some baz:" 5 nil .> "prn from inside hello-world.core" "prn from inside hello-world.macros" nil .> 6 .> 56 .> ------------------------- ...
- Try some things that do not work yet:
.> ////-/.//.:8272 x ^ : 't : ...
License
Copyright © 2015 David Nolen, Rich Hickey, Joel Martin & Contributors
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.