Yesterday, Rich Hickey announced the birth of Clojure – a lisp dialect for the JVM.
After just a brief look, Clojure is perhaps the most interesting language in the (now fairly large) family of ‘dynamic languages for the JVM’. It brings the power of Lisp to the JVM but have made some design decisions that in some ways makes it more interesting than ANSI Common Lisp. Here are some of the things that I find particularly interesting:
- Allows pure functional programming with immutable state (with immutable data-structures etc.) for side-effect-free code (possible in CL but hard to enforce).
- Immutable state can be freely shared across threads.
- Software Transactional Memory (STM) that allows atomic and isolated updates to mutable state (through “Refs”) with rollback and retry upon collision.
- Safe usage of mutable state through thread isolation (using “Vars”).
Great support for concurrent programming:
- Full Lisp-style macro support and eval.
- Compiles to JVM bytecode but still fully dynamic (sounds promising but I don’t know its actual performance).
- Excellent integration with Java APIs, with type inference for static compilation of Java API calls.
Here are some tasters (from the forum).
It is still in beta but if you want to start playing around with it yourself, dive into the docs.
Stuff that I would like to see (in order to make it the ultimate playground) are among other things: message-passing concurrency (I don’t fully believe in STM…yet) and declarative pattern matching (from Erlang), implicit currying and laziness (as in Haskell), transparent distribution (as in Mozart/Oz and Erlang) and optional static typing. Some of these can be found in Qi, I just would love to see them on the JVM.