Clojure: a Lisp-dialect for the JVM – with focus on Functional and Concurrent Programming
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:
Here are some tasters (from the forum).
Java integration:
(new java.util.Date)
=> Wed Oct 17 20:01:38 CEST 2007(. (new java.util.Date) (getTime))
=> 1192644138751(.. System out (println “This is cool!”))
This is cool!
Macros:
(defmacro time [form]
`(let [t0# (. System (currentTimeMillis))
res# ~form
t1# (. System (currentTimeMillis))]
(.. System out (println (strcat "Execution took "
(/ (- t1# t0#) 1000.0) " s")))
res#))Usage:
(defn factorial [n]
(if (< n 2)
1
(time (factorial 1000))
=> Execution took 0.012 s
40…
It is still in beta but if you want to start playing around with it yourself, dive into the docs.
Dreaming on:
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.
Comments