Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start a socket REPL in Clojure 1.8 from leiningen or boot?

Tags:

clojure

In the following link http://clojure.org/reference/repl_and_main#_launching_a_socket_server

it has detailed info about how to start socket REPL form java, but since I am using lein, so how to start from lein. If start from boot is good to run, I could also try to use boot.

like image 663
Daniel Wu Avatar asked Jan 21 '16 14:01

Daniel Wu


People also ask

How do I launch REPL in Clojure?

To start a REPL session in Eclipse, click the Menu option, go to Run As → Clojure Application. This will start a new REPL session in a separate window along with the console output.

How does Clojure REPL work?

So a ClojureScript REPL consists of two parts: the first part is written in Clojure, it handles the REPL UI, and takes care of compiling ClojureScript to JavaScript. This JavaScript code then gets handed over to the second part, the JavaScript environment, which evaluates the code and hands back the result.

What is Clojure REPL?

A Clojure REPL (standing for Read-Eval-Print Loop) is a programming environment which enables the programmer to interact with a running Clojure program and modify it, by evaluating one code expression at a time.


1 Answers

To start a socket repl, you need to pass this option to the JVM

-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"

In Leiningen, add this to your project.clj.

:jvm-opts ["-Dclojure.server.repl={:port 5555 :accept clojure.core.server/repl}"] ; notice that the map is not quoted.

and in Boot, export the environment variable BOOT_JVM_OPTIONS

export BOOT_JVM_OPTIONS='-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"'

Once your REPL is running, you can run telnet from a different terminal to connect to the socket REPL. REPLception!

$ telnet 127.0.0.1 5555
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
user=> (+ 1 1)
2
user=>
like image 141
Daniel Compton Avatar answered Oct 23 '22 05:10

Daniel Compton