-
-
Save abhi18av/a7cdc016db9c6e5b97ce452a3b8db38f to your computer and use it in GitHub Desktop.
Clojure REPL inside Scala program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/dev/scala/cljrepl $ cat build.sbt | |
scalaVersion := "2.11.8" | |
libraryDependencies ++= Seq( | |
"org.clojure" % "clojure" % "1.8.0" | |
) | |
~/dev/scala/cljrepl $ cat src/main/scala/foo.scala | |
import clojure.java.api.Clojure | |
import clojure.java.api.Clojure.{`var` => cvar} | |
object BusinessLogic { | |
val x = Math.random() // I wonder what this value is at runtime... | |
} | |
object Main extends App { | |
val require = cvar("clojure.core","require") | |
require.invoke(Clojure.read("clojure.core.server")) | |
val startServer = cvar("clojure.core.server","start-server") | |
val options = Clojure.read("{:port 4555 :accept clojure.core.server/repl :name repl :server-daemon false}") | |
startServer.invoke(options) | |
} | |
~/dev/scala/cljrepl $ sbt run | |
[info] Loading global plugins from /Users/Borkdude/.sbt/0.13/plugins | |
[info] Set current project to cljrepl (in build file:/Users/Borkdude/Dropbox/dev/scala/cljrepl/) | |
[info] Compiling 1 Scala source to /Users/Borkdude/Dropbox/dev/scala/cljrepl/target/scala-2.11/classes... | |
[info] Running Main | |
------------------------ | |
In a different console: | |
~ $ rlwrap telnet localhost 4555 | |
Trying 127.0.0.1... | |
Connected to localhost. | |
Escape character is '^]'. | |
user=> (import 'BusinessLogic) | |
BusinessLogic | |
user=> (BusinessLogic/x) | |
0.722431948099764 ;; <-- aah! | |
user=> :repl/quit | |
Connection closed by foreign host. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment