I have found a new toy! It is called Clojure. What is it? It is a Lisp dialect that runs on the JVM. Hey, hey, where are you going!
Crap! Around 85% of the readers just left the site in disgust. Some of them have probably un-subscribed from my feed as soon as they saw the word lisp. Oh well, well have to finish this without them.
This gives you a great deal of power and flexibility as you can imagine. This is why I love Rhino which allows me to produce Java compatible code without actually using the Java syntax. Clojure will allow me to do the same thing but with Lisp.
Of course there other JVM implementations of lisp such as Armed Bear Common Lisp (ABCL) or Second Interpreter for Scheme Code (SISC). All of these are fine, but I like Clojure because it seems to be a very progressive project. Instead of simply porting CLISP or Scheme to JVM they decided to create their own flavor, one built from the ground up with Concurrency and Java interop in mind. Traditional lisps don’t do concurrent programming. Since JVM has a great theading support so some of their implementations (like SISC) try to graft it in. But they are bound by backward compatibility and other concerns so the results may vary.
Clojure on the other threads it’s own path, abandoning some traditional conventions and implementing modern ideas. For one it is strongly concurrent, providing interesting abstractions for dealing with synchronous and asynchronous data access problems. Correct me if I’m wrong but I do not thing that any other lisp implementation has such a through and well thought out threading support.
But that’s not all. Clojure natively implements modern data structures such as hash maps and vectors making them behave as functions. Let me show you and example:
(def a (hash-map "foo" "bar" "biz" "bif")) (a "foo") ; returns 'bar'
The language also extends standard lispy sequence functions such as map and filter to all objects that implement the Java iterable interface. So you can easily apply them to all the crazy custom data structures from your legacy code base. It also supports attaching metadata to your objects. It allows you to associate arbitrary map (eg. hash-map) to an object which does not affect that objects hash for comparison purposes, and doesn’t count as part of that object but which can be accessed at any time from within your code.
There is more stuff there but you can read about it on the Closure homepage. The point is that this feels like a new, vibrant language that is going places. When you work with CLISP or Scheme you are dealing with a mature, and pretty much static language. They are pretty much set in stone at this point, and they are very reluctant of introducing new features.
Clojure on the other hand is in active development, and is constantly being improved. It has a thriving community, a well maintained wiki page and a clearly defined set of goals and philosophy. It is a very exciting project – and one of the very few times, that someone is doing some new and exciting things with Lisp. It is a good idea to keep an eye on it. I’m not saying it will become the next big language. I mean, come on – it’s lisp. But it does take lisp into new and interesting directions which is a good thing and for one I’m excited about it.
If you want to start messing around with it, you will need to do three things:
- First download the clojure.jar and put it somewhere
- Second download jline.jar and put it in the same directory (if you skip this part you won’t have history, and left/right arrow support in the console interpreter)
- Make put this bash script somewhere in your path:
#!/bin/bash CLOJURE_DIR=/path/to/clojure CLOJURE_JAR=$CLOJURE_DIR/clojure.jar if [ -z "$1" ]; then java -cp $CLOJURE_DIR/jline.jar:$CLOJURE_JAR jline.ConsoleRunner clojure.lang.Repl else java -cp $CLOJURE_JAR clojure.lang.Script $1 fi
This will allow you to invoke the command line interpreter by calling your script without any arguments, or run a script provided on the command line. That’s all you really need to get started. Or you can just run it from the command line but as with many of these JVM language things these invocations tend to get way to long to type them in by hand each time.
So if you are a Lisp person, or you are interested in learning some lisp go and check it out. You don’t need to install anything. Just download few files, put them in a temporary diectory and start plugging away. If you don’t like it, delete them and your done. How easy is that?