MFave
MFave

Reputation: 1074

Clojure and Atom Proto REPL: Do you always have to manually compile functions from a namespace?

I'm trying to figure out how to be more productive with the REPL tools in clojure, but I'm finding the way namespaces work in a lein project kind of tricky.

When I set up a namespace, something like:

(ns example-ns.core
  (:require [clojure.java.jdbc :as sql]))

And then declare some functions in it (exactly what doesn't really matter for the context of this post).

(defn insert-something! [blah]
  (sql/insert! db :tablename blah))

If I then try to refer something from this namespace I have to manually compile everything I want every time.

(ns example-ns.other
  (:require [example-ns.core :refer [insert-something!]]
            [clojure.java.jdbc :as sql])) 

If I try something like this it will tell me that insert-something! isn't available, unless, I ns into example-ns.core and manually compile it.

Is this necessary? Or am I missing something fundamental?

This wasn't a big deal when I was learning preliminary stuff, but now it's becoming unusable because I'm manually recompiling tonnes of stuff over and over again as the project grows.

This is within the context of a lein project in an Atom text editor with the Proto REPL plugin.

Upvotes: 0

Views: 318

Answers (1)

Alan Thompson
Alan Thompson

Reputation: 29958

I would suggest checking out test-refresh. It helps you to automatically recompile the necessary parts of your project, then re-run unit tests:

https://github.com/jakemcc/lein-test-refresh

Instead of typing something into the repl, just cast it into a unit test (even if it is just a println statement). Then, test-refresh will compile & run it for you and it is very similar to the repl experience (but much better in my opinion).

Upvotes: 1

Related Questions