How to embed REPL to clojure application?


#1

Hi,

I have an application which runs different tasks. It would make debugging much simpler, if I could open a repl inside of the running application. I like to be able to inspect, start/stop tasks, add items to core.async channels… simply control the running application “from inside” using a repl.

How is it possible to reach? I tried to follow https://github.com/clojure/tools.nrepl/blob/master/README.md#embedding-nrepl-starting-a-server, but I could not reach vars defined in the application.

Can you point me to a working example, where in app repl is used?

Thank you,

  George

#2

Hi, George,

I don’t know why you were not able to reach your application vars, are you sure you were in the right namespace? You might need to call in-ns after connecting to your nrepl in order to get there.

Here is the way I have embedded a repl in my own application, and it works the way I expect: https://github.com/brunchboy/afterglow/blob/master/src/afterglow/core.clj#L239-L246

I hope you can get this working because it definitely is helpful!

Cheers,

-James


#3

Hi George,

Sorry I didn’t answer sooner. I was on vacation.

If you’ve managed to connect over nrepl, you’ve accomplished the hardest part. Once you’ve connected, you can navigate around using functions like in-ns https://clojuredocs.org/clojure.core/in-ns

Oh, and now I see that James mentioned the same solution. I often connect CIDER to an nrepl server using M-x cider-connect. It will ask for the host and the port. Then I can use my normal CIDER workflow within (recompiling, inspecting, etc).

Rock on!
Eric