This site uses cookies. Continue to use the site as normal if you are happy with this, or read more about cookies and how to manage them.

×

This site uses cookies. Continue to use the site as normal if you are happy with this, or read more about cookies and how to manage them.

×

QCon - Clojure

I've done some work with Erlang and was impressed by its concurrency model and I'm completely sold on the idea of immutable objects, however, the JVM is an excellent platform which because of Java's prevalence in the marketplace just keeps getting better and better. So it was with interest that I attended the session on Clojure.

Clojure is a lisp dialect designed to run on the JVM.

I was particularly interested in its use of references to manage concurrency. All data structures are immutable, so they can never be in an inconsistent state. However one needs to be able to "update" state as a program runs. Effectively this means replacing the "value" (as complex as that may be) that is "identified" by the reference. So concurrency in this scenario is managing the process where new instances of the data structures are set as the value when multiple clients want to do this at once. Clojure has four types of references:

Refs, these use software transactional memory to ensure co-ordination of updates of the references. Agents, these are asynchronous processes that defer the update until a convenient point in time. Atoms, these synchronously update the references and repeatedly retries in the event of a conflict. Finally, vars, which are isolated so that they are only accessible to the local process.

A major selling point of Clojure is that is runs on the JVM so that one can call it from Java code and vice versa. I'm looking forward to trying it out and seeing how practical it is.