Day 6 - Clojure
Join the DZone community and get the full member experience.Join For Free
Today I'm reviewing the discussion of Clojure from Bruce Tate's Seven Languages in Seven Weeks.
Clojure is Lisp on the Java virtual machine. Lisp is another language
that, despite being around a long time, I have yet to investigate, so
this is another new experience. Bruce starts with a brief review of
Lisp itself, then a quick discussion of the link between Clojure and the
JVM. A discussion of Lisp functions and datatypes is followed by a
view of Clojure lists, sets, maps and vectors (in Clojure, lists are
typically used for data, while vectors are used for data).
Still on Day 1 of Clojure, we discuss functions, including how to pass parameters, deconstruction using bindings, and then anonymous functions. The day ends with an interview with Rich Hickey, the creator of Clojure. One interesting revelation from this interview is that a concerted effort was made to reduce the use of parentheses, to make the language more accessible to the rest of us!
Day 2 discusses recursion, including interesting syntax Clojure uses to support tail recursion (required because of the fact that Clojure runs on the JVM). Next, Bruce discusses Clojure sequences, which can be used to wrap all the Clojure collection classes (plus a few more), and functions available to operate on sequences. He discusses lazy evaluation, used to create infinite sequences. A little discussion on Java interoperability is followed by an overview of macros, used to extend the Clojure language.
Bruce's Day 3 discusses concurrency. Unlike any of the other languages discussed so far in the book, Clojure supports concurrency with an approach that is called software transactional memory, a strategy that uses multiple versions of data to avoid issues surrounding simultaneous mutation. To use this strategy, Clojure requires that all references be changed within a transaction. Following are discussions of working with atoms, agents, and futures. Bruce ends Day 3 with a list of some features of Clojure which were not covered in the book, then ends with the expected discussion of Clojure's strengths and weaknesses.
Opinions expressed by DZone contributors are their own.