Jonas Bonér bio photo

Jonas Bonér

Present.
Entrepreneur.
Hacker.
Public Speaker.
Powder Skier.
Perpetual Learner.
Jazz Fanatic.
Wannabee Musician.

Twitter LinkedIn Github
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).
    • Great support for concurrent programming:
    • 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").
  • 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). 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
       (* n (factorial (- n 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.