1

How to create a REPL for Clojure for which the code is reloadable?

I can create a new project, and get a REPL up and running:

lein new app stack 
cd stack
lein repl
(-main)

Doing the above should get you "Hello, World!".

I would like to stay in the REPL, change the code to println "Howdy partner!", and then just (-main) again. Either auto-reloading or (perhaps even better) simple manual reloading (for instance with a command like (r)) would make the environment complete.

It seems with lein I'm already getting into the right namespace (any namespace but the user namespace from which you then have to (in-ns 'some-ns) is the right namespace!). The only unanswered part is code reloading - either manual or auto.

As it happens I previously asked how to do this with boot.

Community
  • 1
  • 1
Chris Murphy
  • 6,411
  • 1
  • 24
  • 42

2 Answers2

2

For manual reloading you can use the same trick as posted in the boot answer, which is to have a function that does the reloading for you:

(defn r [] (require 'stack.core :reload)) 

Once the above function is part of the stack.core namespace, you can call it from the REPL. Pretty simple - the namespace stack.core has a function in it which reloads itself.

Make code changes from the editor, reload with (r), then run again...

Chris Murphy
  • 6,411
  • 1
  • 24
  • 42
1

There's also the lein-autoreload plugin for automatic reloading.

leeor
  • 17,041
  • 6
  • 34
  • 60