Tuesday, December 2, 2008

Clojure. Wow.

Someone finally did it. They created a LISP that I want to use. Too bad it's for the JVM. :-)

Most of my complaints about LISPs are the same as everyone else's. Few libraries, less documentation, and poor interoperability. I never found a LISP that had everything I wanted. I'm repelled by the complexity of Common Lisp and vexed by Scheme's completely avoidable verbosity. It also find that languages like F# and Haskell do a better job of encouraging practices that minimize mutable state. Putting all that aside, even if a free Lisp with standard libraries as extensive as that of .NET or Java existed I just don't have time to relearn how to print "Hello word," nor should I have to.

Enter Clojure. It runs on the JVM and as such can use any Java library. As for syntax it takes a very conservative approach, adding just enough to make a big difference in readability. Clojure has tremendous potential. Its encourages the use of sequences, has lots of handy immutable data structures, and some nice syntax for creating them. It's weird but Clojure programming feels almost as much like F# as it does Scheme.

I have to call one particular syntactical decision out in particular. The choice of lambda syntax is brilliant:

(reduce #(+ %1 %2) (range 100))

Clojure's got macros (of course), optional type annotations, even a working Software Transactional Memory implementation(!). Having done some simple benchmarking I was pleasantly surprised to find that it's no slouch either.

I have a minor complaint which is that I wish Clojure had adopted JScheme's dot notation for referencing Java class members. I don't find Clojure's approach nearly as readable or natural to a Java programmer. Also there's no way to write mutually recursive functions but that's the JVM's fault.

It's too early to predict whether Clojure will get adopted. My concern is that it will lose out to more syntactically approachable dynamic JVM languages like Jython and JRuby. Frankly I'm not sure I can deal with any more disappointment. I got really excited about Arc. Of course you remember Arc. Paul Grahm's LISP flavor which, after years in the making, took the software development industry by storm. Not.

I don't want to pile on Paul Grahm. He's gotten enough flack over the Arc debacle. There is a lesson here though. If your language doesn't target one of the major VM's you might as well just write a paper and submit it to LtU.

There's no good reason that Clojure couldn't be ported more or less faithfully to .NET. Take the DLR and add some of the classes in F#'s standard library and you're 70% there. It's not like Lisp parsers are hard to write after all. Any takers? I'd do it my self if I wasn't consumed by charting :-).

9 comments:

Anonymous said...

try this: http://www.ikvm.net/userguide/ikvmc.html

Anonymous said...

Great! I will send this link to my friend Bernd. He is a big fan of Lisp

Anonymous said...

Have you checked out Arc? It is an awesome dialect that runs on Scheme. It is all about removing the syntactical bloat.

I haven't heard if anyone's done it but it's possible it could be run on IronScheme.

Judah Gabriel Himango said...

Jafar, I think MS has you working in the wrong department. Silverlight is great, but you're a language geek. They should move you to MSR.

Anonymous said...

in your example of lambda notation you probably meant:

(reduce #(+ %1 %2) (range 100))

Anonymous said...

The capability to do mutual recursion was recently added with the "trampoline" function: see announcement in the Clojure Google group

Anonymous said...

Your example of the lambda notation should just be:

(reduce + (range 100))

Jafar Husain said...

Jeff: I have checked out Arc. I was unmoved. Clojure is much better suited for a fundamentalist functional programmer such as myself.

Erik: How embarassing. Syntax is hard for me give up apparently.

Judah: My love for controls runs deep. Just don't wear it on my sleeve. Wait until the Silverlight charting control stabilizes. Then I'll unleash quite a few SL posts.

Anonymous: Thanks. Although I was aware that I could've shortened that example I expanded it on purpose to show off the %# syntax.

Anonymous said...

Women’s nike tn Shox Rivalry est le modèle féminin le plus tendance de baskets pour le sport. tn chaussuresConcernant la semelle :Cheap Brand Jeans ShopMen Jeans - True Religion Jeans nike shoes & Puma Shoes Online- tn nike, le caoutchouc extérieur, l’EVA intermédiaire et le textile intérieur s’associent pour attribuer à la.ed hardy shirts pretty fitCharlestoncheap columbia jackets. turned a pair of double plays to do the trick.Lacoste Polo Shirts, , Burberry Polo Shirts.wholesale Lacoste polo shirts and cheap polo shirtswith great price.Thank you so much!!cheap polo shirts men'ssweate,gillette mach3 razor bladesfor men.As for

About Me

My photo
I'm a software developer who started programming at age 16 and never saw any reason to stop. I'm working on the Presentation Platform Controls team at Microsoft. My primary interests are functional programming, and Rich Internet Applications.