However, its very fast development progress can make it a little difficult to get started with development, with any tutorial quickly becoming obsolete. To wit, I would suggest taking this guide with a certain level of skepticism if you are not reading it in 2012.
In the first part of the blog I will be stating how to get the basic ClojureScript repl running in the browser and in the second part I will be explaining how to get the repl integrated with Emacs.
git clone git://github.com/clojure/clojurescript.git cd clojurescript ./script/bootstrap
This will get the latest build and all the required dependencies, including
Running the Rhino Repl
Open a new command prompt (do not use the gitbash console) and if you are developing on OSX or Linux you should now be able to run “script/repljs” and get a quick taste of Clojurescript. However, if you are running in windows you will need to invoke script/repljs.bat.
You may see an error as follows.
java.lang.AssertionError: Assert failed: Can't find goog/base.js in classpath
At the time of writing, there is a bug in deploying ClojureScript, as it will always get the head of the Closure Library from SVN. This can cause errors if there are changes in the Closure repository which are incompatible with Clojure. I strongly recommend that you grab the one that I have prepared and works as of 18/05/2012: goog.jar
This jar should be replaced in the clojurescript\lib directory.
You can of course also grab the last Official Closure version from their website and compile it yourself.
Alternatively you can use the goog.jar that Clojure produces, however, if you get google closure errors, then you will need to replace goog.jar, delete the out directory and recompile the .cljs file.
Invoke “script/repljs” or “script/repljs.bak” and you should be able to run a little bit of clojurescript.
(+ 1 2) (print "Hello" " " "World")
Running the Browser Repl
Edit the repljs or repljs.bat file and edit the final line as follows
Change set REPL_CLJ="(require '[cljs.repl :as repl])(require '[cljs.repl.rhino :as rhino])(repl/repl (rhino/repl-env))" to set REPL_CLJ="(require '[cljs.repl :as repl])(require '[cljs.repl.browser :as browser])(repl/repl (browser/repl-env))"
- Navigate up to the directory above clojurescript
- Create a new file called “foo.cljs”
- Create a new file called “index.html”
- Edit foo.cljs as follows
(ns foo (:require [[clojure.browser.repl :as repl]] [[clojure.browser.dom :as dom]])) (repl/connect "http://localhost:9000/repl")
clojurescript/bin/cljsc foo.cljs > foo.js
Edit index.html as follows:
You should now have everything set up. Call
clojurescript/script/repljs #.bat on Windows
Load up the html page.
These should now connect happily
Try the following
(js/alert "Hello World")
Seeing a message like “POST http://localhost:9000/” in the console? You probably haven’t started up the repl! Run “clojurescript/script/repljs”
We will be stating how to integrate emacs into your clojurescript development environment!