Launching the ClojureScript REPL Browser
I am trying to run the ClojureScript REPL in a browser. Ideally, I would like not to use Austin yet: first I want the simplest REPL to work.
I've tried following various tutorials and so far I haven't been able to get it to work. Basically I don't understand what people mean when they say, "Run the ClojureScript REPL browser".
So far I have done:
lein new mies hellow
lein cljsbuild auto hellow
And here is my core.js file:
(ns hellow.core (:require [clojure.browser.repl :as repl])) (enable-console-print!) (println "Hello world!") (. js/console (log "Hello again")) (repl/connect "http://localhost:9000/repl") (. js/console (log "Ah, this prints too"))
, it obviously fails. Chrome developer tools are displayed here.
Failed to load resource http://localhost:9000/repl?xpc=%7B%22cn%22%...
In almost every ClojureScript forum / blog / tutorial I read about this topic, I come across a line that says "Start browser REPL" or something similar.
How do I start the REPL browser? Is this something to be done before loading index.html from the browser?
Can this REPL browser be run from Emacs?
How to check if browser REPL is running without loading index.html / core.js?
How can I check, after index.html / core.js is loaded in the browser, that (repl / connect ...) inside core.js is actually working and is actually connected to the REPL?
source to share
The simplest and easiest way to start a repeater (you already include the client code) is doing
$ lein trampoline cljsbuild repl-listen Running ClojureScript REPL, listening on port 9000. To quit, type: :cljs/quit ClojureScript:cljs.user>
At this point, if you try to evaluate any type expression
(+ 1 2)
, for example, you will see that the variable hangs because it does not have an eval environment.
That when you go to the index.html ( remember to serve it from the webserver or the connection will fail, don't use the urls
) and open it with a browser.
The connection with
should work fine and repl should unlock and print
. From now on, any commands will be executed in the browser environment.
I like to try
to see if repl is connected, if it works it will
hi in the browser window.
Remember that the browser window is your runtime, so if you refresh it, you will lose the runtime values and they will not be available from repl unless you already define them.
Cljsbuild also has: (
lein cljsbuild help
repl-listen Run a REPL that will listen for incoming connections. (the one I used above) repl-launch Run a REPL and launch a custom command to connect to it. repl-rhino Run a Rhino-based REPL (JVM based JS execution environment, no browser needed).
Also, for barebones replica it is useful to use it with rlwrap to get readline quick links (Ctrl + a, etc.) and restore history among other things:
$ rlwrap lein trampoline cljsbuild repl-listen
Hope this all helps.
source to share