Add function to user namespace?


#1

I was reading through the docs for Calva and it has this suggestion,

“Consider adding something like a (start) function in your projects user namespace to pack these calls together.”

It’s talking about stuff to initialize the REPL, so isn’t something that would go in the normal code. So where would it go?


#2

Create user.clj in your src/ directory, looking something like this:

(ns user)

(defn hello []
  (println "Hello!"))

When you start your REPL, you should be able to call (hello) without any imports.


#3

user.clj is also a good place for require’s, so you will not have to reissue them every time you open the REPL.

But better dev/user.clj than src/. The REPL finds user.clj on the Java classpath. Therefore, there should be at-most-one user.clj on the classpath! As a rule of thumb (and definitely, in any project you might share or reuse as a library in another project), put user.clj in dev/ (not src/). When you make a jar or refer to the project with lein checkouts, dev will not be included and user.clj will not become an unwelcome stow-away in your future REPL experiences.