Fork me on GitHub

I want to embed an nrepl server in one of my scripts, but only when enabled via a flag. However just requiring nrepl.server without calling nrepl.server/start-server is enough to prevent the script from exiting immediately. Is this intended? Any workarounds without explicitly quitting at the end of the script?


I also tried to call (require ...) inside a function, but it seems it only works when called on top-level?

(ns test
     [nrepl.server :as nrepl-server]) ;; This is enough to prevent the script from exiting

(println "Hello world")

(defn -main [& args]
  (println "Args:" args)

  (require 'nrepl.server)
  (nrepl.server/start-server :port 7882) ;; This doesn't work, seems that you can only call (require...) at top level?


the nrepl.server/start-server call doesn't compile because that namespace isn't available when you're compiling the -main fn ... I think you need to use something like requiring-resolve ...


maybe something like

(let [start-repl (requiring-resolve nrepl.server/start-server)]
  (start-repl :port 7882))