Thanks to Philip Doctor for teaching us the basics of Clojure at the install-a-thon tonight, graciously hosted by DevMynd. Here are the notes I took on how to get up and running with Clojure on Ubuntu.
First, install Leinengen.
Don't use the package manager—that will install an out-of-date version. Instead, install Leinengen manually.
First, save this script to ~/bin/lein
Change the permissions to make it executable:
chmod 755 lein
Make sure you have JDK version 6 or later.
dpkg --list | grep -i jdk
Now, you can automatically generate a new Clojure project with lein. (First navigate to the directory where you want your project.)
lein new app my_clojure_project
Now you can run your new Clojure project.
You should see output like this:
(Retrieving org/clojure/clojure/1.6.0/clojure-1.6.0.pom from central)
(Retrieving org/clojure/clojure/1.6.0/clojure-1.6.0.jar from central)
You should also write tests, then run them. (Your project will start out with one failing test.)
When you first run lein test, you should see output like this:
lein test my-clojure-project.core-test
lein test :only my-clojure-project.core-test/a-test
FAIL in (a-test) (core_test.clj:7)
FIXME, I fail.
expected: (= 0 1)
actual: (not (= 0 1))
Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
A good place to start learning the syntax (and essence) of Clojure is with the problems on 4clojure.com.