Boot as a sort-of Quicklisp

01 Feb 2016

Really quick: after dismissing Clojure for years (I have Common Lisp, I don’t care about the JVM, why do I need it?) I finally took the time to learn it about a year ago and OMG I love it and I want to use it for everything (much to the dismay of my team at work).

One of the pain points though is how project-based everything seems to be: if you want to pull in any sort of third party library, you have to build some sort of project, be it Maven, Leiningen, or something similar. List the libraries you want to pull in there and start (or restart) your REPL before you can use them.

Coming from Quicklisp, it’s super annoying, especially if you just want to give something a quick spin.

Enter Boot! It’s a relatively new way to handle building Clojure projects, but it allows you to easily name dependencies when you run it, like so:

$ boot -d com.google.code.gson/gson:2.5 repl

That gives me a REPL with Gson loaded and ready to use.

boot.user=> (import [com.google.gson Gson JsonObject])
com.google.gson.JsonObject
boot.user=> (def o (JsonObject.))
#'boot.user/o
boot.user=> (.addProperty o "hello" "world")
nil
boot.user=> (.toJson (Gson.) o)
"{\"hello\":\"world\"}"
boot.user=>

To make life a little easier, I have a task in my ~/.boot/profile.boot that pulls in the dependencies Cider needs:

(deftask cider
  "Switch up the default dependencies and middleware to support cider-nrepl."
  []
  (require 'boot.repl)
  (swap! @(resolve 'boot.repl/*default-dependencies*)
         concat '[[org.clojure/tools.nrepl "0.2.12"]
                  [cider/cider-nrepl "0.10.1"]])
  (swap! @(resolve 'boot.repl/*default-middleware*)
         concat '[cider.nrepl/cider-middleware])
  identity)

So when I want to tool around with something, I just run boot -d whatever:version cider repl, fire up Emacs, connect and go to work.

I haven’t take the time to get comfortable with Boot for full projects yet, so I’m still using Leiningen for most things, but I love it for quick one-off experiments. It’s not as good as being able to load whatever I want from the comfort of the REPL, but it makes things a lot less painful.