xscDev

Something Something Development

Try Clojure libraries with ease using lein-try

with 3 comments

Update (26.07.2013): Added installation to user profile to post (at the bottom).

In this post I’ll not advertise one of my own projects but instead direct your attention towards the awesomeness that is Ryan Neufeld’s lein-try. Imagine you’re browsing the intertubes and you discover a blog post/GitHub page/etc… outlining an interesting library, say Peter Taoussanis’ nippy. You feel you want to try it – you need to try it – and you want to do that immediately.

This is how you’d probably do it, having never heard of lein-try:

  1. Create a new project, e.g. “nippy-test”:

    lein new nippy-test
  2. Modify the “project.clj” to include nippy:
    ...
      :dependencies [[org.clojure/clojure "1.5.1"]
                     [com.taoensso/nippy "2.0.0"]]
    ...
  3. Start a REPL:
    lein repl
  4. Use nippy.

Behold, lein-try can speed things up drastically. You do not have to create a project, you do not have to modify your project.clj – and the REPL is part of the deal. Just pass any artifacts you’d like to try to it (either with “[…]” or without):

$ lein try com.taoensso/nippy "2.0.0"
Retrieving com/taoensso/nippy/2.0.0/nippy-2.0.0.pom from clojars
Retrieving expectations/expectations/1.4.49/expectations-1.4.49.pom from clojars
...
nREPL server started on port 59952
REPL-y 0.2.0
Clojure 1.5.1
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)

user=>

Fire away!

(require '[taoensso.nippy :as nippy])
(def s (nippy/freeze {:hello "world"})) ;; => #'user/s
(map int s)                             ;; => (78 80 89 1 25 96 ...)
(nippy/thaw s)                          ;; => {:hello "world"}

That’s it, from zero to nippy in one line. Try it out by adding the plugin to your ~/.lein/profiles.clj:

{:user {...
        :plugins [... [lein-try "0.2.0"] ... ]
        ...}
 ...}

Written by Yannick

July 26th, 2013 at 1:36 pm

  • rkneufeld

    This is awesome, thanks for writing this up! My only feedback would be that you may want to include a note about adding lein-try to ~/.lein/profiles.clj (https://github.com/rkneufeld/lein-try#leiningen-via-clojars).

    • http://dev.xscheme.de/ Yannick

      I added a short description of how to install lein-try at the bottom of the post.

      Glad you liked it.

  • Keith

    Very helpful!!! Thanks for posting and thanks for writing Ryan