Clojure becomes more portable

There has been a flurry of activity on Twitter after Rich Hickey’s recent announcement of ClojureScript. Clojure was initially developed for the Java Virtual Machine, and although there has been a project to port it to the Microsoft CLR (with only limited success), this development looks like it will radically extend the usefulness of the language. ClojureScript is a subset of Clojure, and I assume they’ll take the opportunity to get rid of parts of the language that aren’t really used in production applications. For example, use of eval is typically frowned upon by Lisp developers.

For me, the highlights are that the ClojureScript compiler is written in Clojure. The standard Clojure implementation has a compiler written in Java and a library that is written mainly in Clojure requiring work in two languages to extend it. Writing the compiler in the language itself means that improvements in the language can lead to improvements to the compiler too.

The ClojureScript system also uses the Google Closure compiler to post-process the generated Javascript. The Closure compiler is used by Google to optimise its various Javascript applications such as Gmail. It does a number of sophisticated compiler optimisations including tree shaking to get rid of code that will never be used by the application, leading to very small executables. There are several blog posts about this, including the start of a series by one of the developers here.

There have been other languages that compile down to Javascript, including the seminal GWT which has been successfully used to write large applications. I imagine the only difficulty is the debugging story – as a programmer who wrote the application in one language, it may be hard to understand the mapping to another language in order to debug the final application.

Clojure will now be able to run on top of various App Engines such as node.js, and there is even a REPL that runs on top of Javascript engine Rhino. When running in the browser, ClojureScript applications will now be able to use Javascript libraries such as jQuery.

It will be interesting to see how far ClojureScript is developed, and where this leaves the standard Java implementation. There is some discussion on Hacker News.

Advertisements
This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s