April 13, 2012

From Python to Clojure: What I miss.

Part of an ongoing serious about my delving into Clojure. I've returned to a Python project for a bit, only to find that a language I characterized as "the ideal general-purpose language" only last month seems... well, constraining. After 30 minutes of Python coding, here's what I've run up against:

The anonymous function syntax is incomplete. I never minded before, but coming back with a few new tricks, I find myself running into it more often. No statements means nothing so much as a conditional within a lambda. Of course, as the wikipedia article points out, I could just as well create a named function. But of course it's not just about what I could do, but about convenience. Other languages do this better; I'm a particular fan of coffeescript's (x) -> x * x, which is also incidentally a language with whitespace-defined blocks.

The functools library is a touch sparse. I went in looking for a compose, and came out empty-handed. If course, one can write one's own, but one comes to expect such things should be common enough to be present in functools to begin with. At least partial was where I expected it.

Did I mention macros? Faced with the limitations of lambda above, I immediately started writing an "if" function analogous to clojure's if form -- only to of course realize that without compile-time macros there was no way to do it without evaluating the arguments, or otherwise doing something not allowed in lambda. It's been just a month since I first tried clojure, and already I take macros for granted.

And finally, the REPL, and integration with Vim thereof, was sorely missed. This is still perhaps the greatest selling point for any lisp.

Of course, I'm not suggesting that richer lambdas and more functional tools be bolted on to python; it has its place, and it's still very very good at what it does. And after all, as Mr. Turing observed all those years ago, you really can write about any program in any (sufficient) language. It just feels good to have risen above Blub by just a little bit. If I can, you can.