Mostly about Clojure and ClojureScript

One Off Experiments With Clojure and ClojureScript Libraries

Oct19th, 20164:19 pm

Did you ever need to know the date and time 30 hours from now,
because that is the time you could check into your plane to
EuroClojure 2016 (and you’re too lazy to do this in your head)? Or
maybe you just saw an interesting Clojure library on Twitter or Reddit
that you wanted to try out? How convenient would it be if you didn’t
have to create a project for such one off experiments.

There are several good options in Clojure for this. In this post let’s
assume we were going to try
out clj-time, an excellent
date and time library based on Joda Time. We’ll show how to make a
script that gives you almost instantaneous access to this library from
the command line using Boot. And then we’ll
make it even faster using Planck.

Leiningen

For Leiningen, there
is lein try. This is a plugin
you can install into ~/.lein/profiles.clj. Then from the command
line, just type lein try clj-time and we’re good to go:

Boot

For Boot this story seems even simpler as there
is no need to install a plugin. Boot supports an option for including
dependencies from the command line. Just type boot -d clj-time repl
to get a REPL with the latest clj-time as a dependency:

Final thoughts

Typing directly in a REPL only goes so far. For larger expressions it
is more convenient to write in a text editor and then send the code to
the REPL. For experiments started with Leiningen or Boot you can use
an nREPL client. I
use CIDER. For Planck you
can use inf-clojure.

That’s it. I hope this also helpful to beginners. Performing little
Clojure experiments can grow into an addiction. Before you know it,
you’re soaked into your first Clojure project.