First steps into clojure
I’ve been looking for a new language to learn.
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:
- Using the REPL, a command line environment where you can just try clojure commands;
- Having the ability to build a small application and run tests on it, like a maven project where I can have my code, my tests, build the project and have a deliverable at the end.
So here we go!
- (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;
- 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;
- 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
- 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.
- With that project created, cd into its directory and try
lein helpwill give you a list of options you can use but the one that’s really nice is
lein pom– it generates a
POMfile for your project, which means that you can now import it into IntelliJ;
- 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. :-)