How to reload an app in the REPL with Clojure

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

I have been working with Clojure now for much of the last 18 months, so I am no longer a complete noob. But I was slow to get used to working at the REPL. Working with the REPL is taken for granted in the Clojure community, so much so it is tough to find step-by-step instructions for doing it. For me, a confusing issue for a long while was, if I wanted to get back into an app, what are the steps? So this is the workflow I figured out:

1.) start emacs

2.) open a file in the project that I want to work in. I usually start by opening up the project.clj fie.

3.) type nrepl-jack-in to launch the repl.

4.) load whatever file holds the (main-) function that starts the app. So for me, for instance, it might be:

(load-file “src/admin/core.clj”)

5.) switch to that namespace:
(in-ns ‘admin.core)

6.) call the function that starts your app: (main-). Give it any arguments that it needs. I write mine with :pre asserts that throw errors in case I forget to give the correct arguments.

7.) do whatever work you want to do. Moving around inside of the project tends to consist of a lot of loading a file:

(load-file “src/admin/controller.clj”)

and then switching to the namespace:

(in-ns ‘admin.controller)

Source