Clojure: Lisp meets Java, with a side of Erlang

Stuart Sierra on why Clojure is catching on.

ClojureClojure seems to be the hot new language of the moment, attracting both Java developers and hackers who remember Lisp with fond memories. To see what all the buzz was about, I talked to Stuart Sierra (@stuartsierra), a Clojure developer and author of “Practical Clojure.” Sierra will be speaking about Clojure in next month’s OSCON Java track.

What is Clojure? How does it differ from functional languages like Erlang?

Stuart SierraStuart Sierra: Clojure is a new programming language that runs on the Java Virtual Machine. It’s in the Lisp family of languages and it’s a general purpose language, but it emphasizes a functional programming style with tools to manage shared state in large multi-threaded programs.

It’s similar to Erlang with its emphasis on functional programming, but whereas Erlang is designed for systems distributed across many machines, Clojure focuses on many threads within a single machine. Erlang is trying to solve the very difficult problem of making everything parellelizable across multiple machines. Clojure is doing something different. It’s trying to make sure that many threads in the same machine can safely share state.

How similar is Clojure to the syntax of traditional Lisp-like languages?

Stuart Sierra: Clojure is probably a little bit closer to Common Lisp than Scheme in style. It would not be particularly difficult for someone with Lisp experience to pick it up, although they would have to learn about some of the differences in the syntax. Clojure has a little bit more syntax than Common Lisp or Scheme, so it’s actually a little easier to read and it has fewer parentheses than Lisp-like languages typically do. We’ve done examples where we put Java code and the equivalent Clojure code side-by-side and there are the same number or fewer parenthesis in the Clojure code because it’s so much shorter.

OSCON Java 2011, being held July 25-27 in Portland, Ore., is focused on open source technologies that make up the Java ecosystem. (This event is co-located with OSCON.)

Save 20% on registration with the code OS11RAD

Some developers have a visceral negative reaction to Lisp. Why do you think that is?

Stuart Sierra: I think the problem people often have with Lisp is based on first encountering it in an academic setting, and the particular Lisp language they were using was designed for academic purposes. Scheme, in particular, came out of academia, and that focus has often made it more difficult to use for real-world applications. Clojure, on the other hand, is a very pragmatic language. It was designed by a career programmer, Rich Hickey, who wanted to solve real problems that he had with other programming languages. So if you can get over the initial similarities with Lisps that you might have seen before, I think you’ll find that Clojure is a very productive language to work with.

Is Clojure being used in large-scale production?

Stuart Sierra: Yes, there are many “success stories” listed on the Clojure website and more on our wiki. I work for a company, Relevance, that does consulting for enterprise software, and we’ve had several client projects written in Clojure that have been quite successful. It’s also been used in production by Akamai, financial companies, big data companies that are doing large data processing, and in a variety of other places.

The Java Virtual Machine (JVM) seems to be the language platform of choice for developing languages. What makes the JVM so attractive, and how does Clojure leverage it?

Stuart Sierra: The JVM makes an excellent platform for language development, and that’s why we’ve seen so many new languages show up. It’s actually much better as a target for languages than some lower-level assembly-type languages for the simple reason that it provides a way for all of those different languages to interoperate. So now you can have Clojure code, JRuby code, Scala code and Java code all making use of the same libraries and all calling back and forth to one another. So a Java method call in Clojure looks like a Clojure function call, but you’re calling a Java method call by name. That compiles to a normal Java method call that has all of the performance benefits that the JVM can provide. You can define classes in Clojure that will be available to Java programs and accessible to Java programmers through the standard calling conventions that they’re used to. All of Clojure’s built-in data types implement the standard Java collection interfaces, so they can be passed directly into Java code without changes.

What’s the IDE situation for Clojure?

Stuart Sierra: IDE support is evolving. There are plug-ins available now in varying states of sophistication for all of the major IDEs: Eclipse, IntelliJ, NetBeans. A lot of people are also using Emacs or another sophisticated text editor with good support for writing Lisp-like languages.


tags: , , , ,

Get the O’Reilly Programming Newsletter

Weekly insight from industry insiders. Plus exclusive content and offers.

Comments are closed.