Monday, February 7, 2011

Clojure: easiest installation ever

Some time ago I wrote a post about installing Clojure on windows. It was about the manual installation of clojure on Windows, without using leiningen or other external tools. My idea was to write more posts about installing and setting up the environment on OS X (and perhaps Linux, though I suspected that the steps would be the same). Then perhaps introduce Leiningen.

In fact, Leiningen is too simple to install to deserve an article on its own. On windows it is a matter of downloading a bat file an running it. On Unix substitute the bat file with a shell script and you get the idea. It is exactly the way software should be deployed. If installation instructions are not dead simple, users will follow different paths and even support becomes far more complicated.

Besides, leiningen on OS X is just a matter of:
% brew install leiningen

Why we insist on Leiningen? Afterall it is a "build tool for Clojure designed to not set your hair on fire." The next line in the description once again states that:
Building Clojure projects with tools designed for Java can be an exercise in frustration. With Leiningen, you describe your build with Clojure.

From the description, it seems that Leiningen is essentially a project oriented tool. I have lots of reluctance about "project oriented tools", especially when I'm starting to work with a new environment. I want to use it to write small scripts in order to become more confident and more productive with the environment, without tackling both the novelty of the environment and the problems related to a medium size project. Moreover, I want to write small IA games, project euler problems... and lots of stuff which is not project oriented.

This is the reason why I wrote the article which described how to install clojure as a "regular interpreter" that can be used as I would use Python or SBCL. In fact, clojure is that and even more, but I have to focus. Why leiningen? Leiningen is a project oriented tool.

The fact is that leiningen is so simple that it is not harder to setup a full project than a single file. In fact it suffices:

% lein new leiningen-examples
Created new project in: /Users/enrico/Documents/src/leiningen-examples

And I have got the skeleton of the project, which contains instructions about installing both clojure and clojure-contrib (which is useful and I always forget to install until I need it). Lein will download the clojure (and other jar) dependencies. Lein will run your repl (with the relevant libraries included), bundle everything in a single jar, and so on. This is great... still, I miss a full-fledged sistem-wide installation.

Once again, brew comes to my help:
% brew install clojure

Some of my needs are fullfilled. Consider for example:

% cat prova.clj     
#!/usr/bin/env clj

(println (slurp "http://www.google.com"))

% chmod 755 prova.clj
% ./prova.clj       
--- google homepage

However, the repl is not half as good as the one I got from leiningen. E.g., readline-like support is not available by default (differently from my post on Windows). I can always add clojure-contrib with brew:

% brew install clojure-contrib

and brew suggests:

==> Caveats
For Clojure to detect the contrib libs, the following path must be in your
CLASSPATH ENV variable:

    /usr/local/Cellar/clojure-contrib/1.2.0/clojure-contrib.jar

To do this with bash, add the following to your ~/.profile file:

    export CLASSPATH=$CLASSPATH:/usr/local/Cellar/clojure-contrib/1.2.0/clojure-contrib.jar

The suggestion actually works. However, we are still issues with readline.



, ,

No comments: