Help understanding relationships between nREPL, REPL-y, lein, and cider

183 views
Skip to first unread message

John Gabriele

unread,
Apr 1, 2015, 10:27:00 AM4/1/15
to clojur...@googlegroups.com
Hi, all. Hoping to understand how all these pieces fit together:

  * Does "nREPL" (github.com/clojure/tools.nrepl) refer to not only "an nREPL server" but also "the nREPL protocol"?

  * I see that nREPL provides an nREPL server. Does it also provide a client?

  * Is REPL-y (github.com/trptcolin/reply) an nREPL client? If so, is it typically used in preference to the one that comes with nREPL?

  * Is Leiningen the primary user of REPL-y?

  * I see that, when I run `lein repl` in a project, lein starts up an nREPL server process. Does it also start an nREPL client? A REPL-y client? What is talking to whom when I type in code at the lein repl?

  * Does cider implement its own nREPL client in elisp? The cider README say it is "built on top of nREPL" ... what exactly is meant by that?

  * If I want to use Emacs + cider, what is the difference between using "M-x cider-jack-in" vs. "M-x cider-connect"? Does one require more JVM processes than the other?
 
Thanks so much!

Colin Jones

unread,
Apr 1, 2015, 10:50:33 AM4/1/15
to clojur...@googlegroups.com
On Wed, Apr 1, 2015 at 4:01 AM, John Gabriele <jmg...@gmail.com> wrote:
Hi, all. Hoping to understand how all these pieces fit together:

  * Does "nREPL" (github.com/clojure/tools.nrepl) refer to not only "an nREPL server" but also "the nREPL protocol"?


I typically think of it as the protocol and say "nREPL server" for the server itself.

 
  * I see that nREPL provides an nREPL server. Does it also provide a client?



 
  * Is REPL-y (github.com/trptcolin/reply) an nREPL client? If so, is it typically used in preference to the one that comes with nREPL?


Yes (see above) - I have a long-standing issue to separate the jline and completion bits from the nrepl communication bits (https://github.com/trptcolin/reply/issues/68), but there hasn't really been any demand for it.
 
 
  * Is Leiningen the primary user of REPL-y?


Yes, I'd say Leiningen is certainly the primary user in terms of # of people using it. Boot uses it too, as well as several end-user applications I know about (and I assume some that I don't).

 
  * I see that, when I run `lein repl` in a project, lein starts up an nREPL server process. Does it also start an nREPL client? A REPL-y client? What is talking to whom when I type in code at the lein repl?


Yes, `lein repl` will start a REPL-y client (which is an nREPL client). `lein repl :headless` will start only the nREPL server (no client at all), and `lein repl :connect` will start up only the client: https://github.com/technomancy/leiningen/blob/34d62f8f57ea20e74c7dcb35b20d368292cf716b/src/leiningen/repl.clj#L279-L292

But yeah, the normal `lein repl` starts an nREPL server (in the project JVM) and an nREPL client [REPLy] (in the leiningen JVM).

 
  * Does cider implement its own nREPL client in elisp? The cider README say it is "built on top of nREPL" ... what exactly is meant by that?

  * If I want to use Emacs + cider, what is the difference between using "M-x cider-jack-in" vs. "M-x cider-connect"? Does one require more JVM processes than the other?

I'm no help on the emacs side of things, sorry!
 
 
Thanks so much!

--
You received this message because you are subscribed to the Google Groups "clojure-tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-tool...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Colin Jones
@trptcolin

Michael Griffiths

unread,
Apr 1, 2015, 10:57:59 AM4/1/15
to clojur...@googlegroups.com
Hi John,
 
I can help on the emacs side :-).
 
* Yes, CIDER implements an nREPL client that assumes it will communicate with nREPL over a socket, with messages encoded in Bencode (which is the default). It lives in `nrepl-client.el` in the CIDER repo, if you want to take a look at the source.
 
* `cider-jack-in` will start a new nREPL server (via `lein repl :headless` by default) whereas `cider-connect` will connect to an already-running nREPL server. I think 99% of the time people use the former, unless they need to connect to an already-running application that has an embedded nREPL server.
 
btw: note that `lein trampoline repl` does not (AFAIK) start an nREPL server. See the `trampoline-repl` function that Colin linked to above.
 
Thanks,
 
Michael

Chas Emerick

unread,
Apr 1, 2015, 1:56:15 PM4/1/15
to clojur...@googlegroups.com


On 04/01/2015 10:50 AM, Colin Jones wrote:
On Wed, Apr 1, 2015 at 4:01 AM, John Gabriele <jmg...@gmail.com> wrote:
  * I see that nREPL provides an nREPL server. Does it also provide a client?



Minor correction: the cmdline namespace that Colin refers to is a teletype interface, that is, yes, just a spike that was intended only as a demonstration. It does this using the Clojure client that tools.nrepl does provide, in clojure.tools.nrepl:

https://github.com/clojure/tools.nrepl/blob/master/src/main/clojure/clojure/tools/nrepl.clj

AFAIK, the above is the primary (sole?) Clojure nREPL client that various tools use.

Apologies for any ambiguity I've helped foster around the nomenclature.

- Chas

Colin Jones

unread,
Apr 1, 2015, 2:12:02 PM4/1/15
to clojur...@googlegroups.com
Whoops! Thanks Chas!

--
You received this message because you are subscribed to the Google Groups "clojure-tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-tool...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Colin Jones
@trptcolin

John Gabriele

unread,
Apr 1, 2015, 4:26:55 PM4/1/15
to clojur...@googlegroups.com

Ok, I see: The proof-of-concept command-line client for nREPL (residing in clojure.tools.nrepl.cmdline) is the primary (possibly sole) Clojure nREPL client which uses clojure.tools.nrepl/client.

Chas Emerick

unread,
Apr 2, 2015, 6:10:58 AM4/2/15
to clojur...@googlegroups.com
No, I was saying exactly the opposite, that clojure.tools.nrepl is used widely, e.g. in reply here: https://github.com/trptcolin/reply/blob/69c4c6ffe0c8903a193c1e127337832e225335b0/src/clj/reply/eval_modes/nrepl.clj#L199

It is the cmdline.clj demonstration bits that are unused.

- Chas

John Gabriele

unread,
Apr 2, 2015, 11:43:40 AM4/2/15
to clojur...@googlegroups.com
 
  * I see that, when I run `lein repl` in a project, lein starts up an nREPL server process. Does it also start an nREPL client? A REPL-y client? What is talking to whom when I type in code at the lein repl?


Yes, `lein repl` will start a REPL-y client (which is an nREPL client). `lein repl :headless` will start only the nREPL server (no client at all), and `lein repl :connect` will start up only the client: https://github.com/technomancy/leiningen/blob/34d62f8f57ea20e74c7dcb35b20d368292cf716b/src/leiningen/repl.clj#L279-L292

But yeah, the normal `lein repl` starts an nREPL server (in the project JVM) and an nREPL client [REPLy] (in the leiningen JVM).


 
Colin, thanks so much! Very useful info indeed.

I also see that, when I start up `lein repl`, the nREPL server process is actually a child process that `lein repl` starts.

So, when I start up `lein repl` in my clojure app's project:

 #. lein kicks off another process to run nREPL server. nREPL server must load my code in some way, and set the current namespace accordingly.

 #. lein then loads and runs REPL-y, pointing it at the nREPL server.

I tried out using `lein repl :headless`, and then can connect to it from another terminal via `lein repl :connect localhost:12345` (or whatever port `lein repl :headless reports it's listening on). :) (Though, I see that `lein repl :headless` still creates 2 processes (one for lein's JVM and one for nREPL's).)

-- John

John Gabriele

unread,
Apr 2, 2015, 11:52:44 AM4/2/15
to clojur...@googlegroups.com

Thanks for the clarification, Chas.

So, is the nREPL client that comes with tools.nrepl somewhat lower-level than the more featureful REPL-y (which, under the hood, makes use of the tools.nrepl nREPL client)?

(Aside: in tools.nrepl's clojure/tools/nrepl/server.clj, it appears that the "[clojure.tools.nrepl :as repl]" in the ns's :require goes unused.)

By the way, does the repl that comes with the clojure jar (the one I get via `java -cp clojure-1.6.0.jar clojure.main`) act as both repl client and repl server? (I assume it of course uses neither nREPL server/client nor REPL-y).

John Gabriele

unread,
Apr 2, 2015, 2:16:08 PM4/2/15
to clojur...@googlegroups.com
Thanks Michael!

-- John
Reply all
Reply to author
Forward
0 new messages