Ambly and Socket REPL

November 11, 2015

Clojure 1.8.0 will be introducing a new Socket REPL capability that will make it easier to integrate tooling with REPLs. Perhaps a succinct way of looking at it, is that it is an improved take on what nREPL offers.

It turns out that this capability works just fine with ClojureScript REPLs. So I gave it a spin with Ambly, and it appears to work properly, even with Ambly's special "device discovery" CLI that occurs when it is starting up.

Here's a demo: In a Clojure REPL set up with Ambly 0.6.0, Clojure 1.8.0-RC1, and ClojureScript 1.7.170 on the classpath, issue these 3 forms:

(ns ambly-repl.core
    [cljs.repl :as repl]
    [ambly.core :as ambly]
    [clojure.core.server :as server]))

(defn make-repl []
  (repl/repl (ambly/repl-env)))

  {:port 51000
   :name :cljs-socket-repl
   :accept 'ambly-repl.core/make-repl})

Then you will see

#object[ 0x7d4a2ef4 "ServerSocket[addr=localhost/,localport=51000]"]

Then, in another terminal use telnet as the Socket REPL client:

$ telnet 51000
Connected to localhost.
Escape character is '^]'.

[1] Ambly Demo on Mike's iPhone

[R] Refresh

Choice: 1

Connecting to Ambly Demo on Mike's iPhone ...

To quit, type: :cljs/quit
cljs.user=> (map inc [1 2 3])        
(2 3 4)

Cool! I'm communicating with Ambly over a socket, which in turn is communicating with my iPhone via TCP over WiFi. All good!

My take away is that it will be very easy to expose the capabilities of REPLs over a socket, and I'm looking forward to tooling (especially IDEs like my favorite one, Cursive) to be enhanced to support Socket REPL.

Tags: Ambly ClojureScript