Last night the wmassdevs Group hosted a Clojure presentation by Rich Hickey. Clojure was born of Rich's dissatisfaction with the current state of the concurrent programming and so was built from the ground up around the idea of making this task less painful. Previously, I had never really looked closely at Clojure but I was struck by some of the really inventive ideas rolled into it.

Immutable data structures have been heralded as the solution to all of our concurrent programming woes but copying a data structure each time you use it produces a ridiculous amount of overhead. To avoid this, F# represents it's data structures as Binary Reference Trees and only replaces references as necessary. Clojure takes this one more step and uses Bit Partitioned Hash Trees. This reduces the immutable data structure overhead further by reducing the depth of the tree. It is extremely important to make the overhead involved as small as possible because lower overhead means more likely people are to jump on the immutable bandwagon.

Another big problem with concurrent programming is sharing information between threads. People have written external libraries to support Software Transactional Memory and Erlang style Agents in F# but they are not part of the language or it's packaged libraries. Clojure on the other hand, natively supports three different types of data handling:
Vars which isolate change within their scope.
Refs which are used as transactional memory.
Agents which, as you might expect, are used as asynchronous workers.

Having all of this built into the language from the start is huge.

Although I think Clojure is a fantastic language I do have a couple of constructive criticisms. As a dialect of lisp, it could be hard to organize your data along with your functions of that data effectively. I think F# wins here because of it's Object Oriented nature. I also noticed that many of the functions in Rich's demo were only supposed to be called from within a transaction. It would be good if there was some way to enforce that.

At the end of the presentation he walked us through a 500 or so line ant colony simulation. It was really quite easy to understand as far as lisp implementations go. As all the pieces of the demo came together it became clear exactly what would happen in this hugely multi-threaded program. It was a shocking moment of clarity: seeing 60 threads working together with no locks and knowing the behavior of each of them exactly.