Posted on August 25, 2012

First steps into clojure

I’ve been looking for a new language to learn.

Javascript and Java are currently part of my job, so all the new things I have to learn in those languages I already do them every day. Besides they are quite mainstream and I wanted something a but more exotic, like Functional Programming.

I had peaked into Scala a couple of times already but I’m (still?) not convinced of the whole scalable language concept. Maybe it’s immaturity on my part but since I’m only 31, there’s still hope for me I guess.

Since I like the idea of staying in the JVM ecossystems, the other option was clojure.

I had Lisp in university and I enjoyed it a lot. I remember that my good friend Hubert was a big fan of Clojure. and since he was one of the few truly inspiring people with whom I worked at Tomtom, I guess I could just follow his lead on this one.

So, if you’re jsut like me, thinking of how to start, I’ll describe the general setup you’ll want to have so that you can play with Clojure in two different ways:

So here we go!

  1. (Leiningen) – leiningen is the Clojure equivalent to Maven. And it integrates with Maven in such a beautiful way that it’s not even real. Get it the old-fashioned way since package managers are still using the older clojure 1.3.0;
  2. So, since lein is like maven, it downloads whatever dependencies you may need, one of them being… Clojure. Its dependencies come from Clojars, the clojure equivalent to Maven Central and also from maven central;
  3. Now, it turns out that with lein you immediately have both the REPL and a way to create new project. To try the REPL just do lein repl;
  4. To create a new project do lein new awesome-project. That is the equivalent to mvn archetype:generate, except it doesn’t ask you for anything – and creates a proper project.
  5. With that project created, cd into its directory and try lein test, lein clean, lein install. lein help will give you a list of options you can use but the one that’s really nice is lein pom – it generates a POM file for your project, which means that you can now import it into IntelliJ;
  6. La Clojure) is the plugin you’ll want to use if you use IntelliJ. Head over o intellij, open the plugins, search for clojure, choose La Clojure, install and restart. now import your project from the pom file you created above.

So, my first observation is that things just seem to work. Batteries included kind of way.

You get leiningen and it is working without any configuration. You create a pom file and it’s valid and intellij reads it. The project that was generated with lein new has a documentation folder with a doc written in markdown.

The people behind this seem to follow this idea of “convention over configuration” and that is so refreshing.

So my next question is how to approach learning this.

I’ve seen a lot of lisp exercises out there but I also keep seeing that clojure is not exactly lisp, so they may not be the option.

I really loathe project euler since I’m not trying to exercise my brain or remember mathematics here - I’m looking for programming exercises, algorithmic problems, that make me understand the way you do things in clojure. Something that would guide me through the standard API, while at the same time forcing me to solve little problems.

4 clojure may be a good candidate, although it looks a lot like project euler.

I thought of following the python challenge, has the kind of problems I’m talking about. Another option is Land of Lisp, where you create a game every chapter - but again, it uses common Lisp instead of clojure

Nothing is ever finished, it seems. :-)