Learning Clojure

Clojure is a new functional language for the JVM. This post is a collection of links, articles, screencasts and free books I’ve found to help me learn the language and understand functional program design.

clojure icon

Key features

Here are some key features of Clojure that I find extremely interesting:

  • Designed for concurrency
  • A Lisp dialect – functional, not mixed-paradigm like Scala
  • Compiles to Java bytecode
  • Easy interoperability with Java libraries
  • Immutable data structures
  • Manage state with transactions

A lot of this seems to blow away the languages I use on a regular basis, like Ruby and PHP. Furthermore I’ve had some misgivings lately about the gaggle of run-times I end up using as a multi-language programmer using mostly interpreted languages. So the fact that Clojure compiles to Java bytecode is a real selling point for me, despite my historical avoidance of Java.

An editor

You’ll need an editor to start working with Clojure. Though I’m a Vim user, I could not get VimClojure working right on my machine. Drop me a line if you got it running – hurray for you!

If you are on Windows, I recommend the super-easy-to-install Clojure Box. After a couple of clicks, you’ll have Emacs and a working Clojure REPL. “REPL” stands for Read/Eval/Print/Loop. It’s like IRB for Ruby; an interactive development tool. Emacs makes it easy to pass code into the REPL from an editing buffer, which of course you could do with a bit more elbow grease from Vim using a REPL you spawned on the command line.

Some theory

Now you need to beef up on why Clojure is awesome. The best place is the horse’s mouth: Rich Hickey, the creator of Clojure, has released a number of essays, screencasts and lecture notes describing the benefits of his language.

Screencasts

Essays

Syntax

Time to start writing some code! A great place for an overview is the Clojure home page. However, the site can be a little overwhelming or, if you read it a bunch of times, underwhelming. So it is time to branch out and see what the world has to offer.

What we are looking for are introductory examples of Clojure code and more advanced samples of real code.

Blog posts

Not-Free Books

Sometimes, you just need to read a book. Right now, there isn’t much published about Clojure – but I recommend Stuart Halloway’s Programming Clojure.

Otherwise, a bunch of books are in “alpha” or pre-release stages from the major book publishers, so the dearth of material should improve by the end of 2010 and early 2011, I assume.

Functional programming

The big elephant in the room! The design of Clojure programs is — or ought to be — different than those written in object-oriented languages like Ruby and Java. I am still wrestling with functional program design, but thanks to the Clojure community and a lot of Googling I have found some sources to help.

Free books

Since Clojure is a Lisp, reading books on Lisp seems like the best approach to learning about the kind of designs that fit naturally into Clojure. Of course, there is also the awesome factor that your programs can interact with Java libraries, which changes things. But if, like me, you have never programmed in a Lisp or any functional language, then — first things first, as the saying goes.

Blog posts

Community

Really, the best thing would probably be to join the Clojure Google group, and to search the archives for questions you might have. A lot of OO language people seem to wash up on the Clojure beach and they (we) tend to have similar questions.