I’ve been meaning to get back to Lisp for a while. Clojure meanwhile has been evolving as one of the up and coming languages. Perfect time to have a play.
If a language has a REPL I’m not going to start writing in an editor without a good interaction with that. First stop, Stack Overflow for suggestions. Lots of votes for Emacs? Time to find out how good my muscle memory is from a few years ago then.
~/.emacs.d/init.el add the following
The last line adds a good source of Clojure packages to the list. Now start Emacs and use
M-x package-list-packages. You probably want
clojure-mode swank-clojure slime slime-repl
slime-clj but that seemed to break stuff for me.) Mark those with
i and hit
x to install them. That’s the Emacs side done.
Technomancy’s Leiningen seems the recommended route to package and project management for Clojure. And so far it is so easy I haven’t bothered looking for anything else. Download it from Github and follow the installation instructions (i.e. put it in your path). Create your first project via
lein new clj-test
To get Emacs and your project talking, in theory you should be able to open
clj-test/project.clj (or anything else beneath the project directory) in Emacs and use
M-x clojure-jack-in. That didn’t work for me so I’m currently using the two stage approach of running
lein swank from a terminal in the project directory and
M-x slime-connect in Emacs.
Now go write code.
One of the nice things about Leiningen is that it sets up unit test stuff for you. So as you put code into
you can put tests into
And these are run simply with
$ lein test Testing clj-test.test.core branch index 0 remaining 0 Ran 4 tests containing 4 assertions. 0 failures, 0 errors.
For the purposes of learning the language I’m really enjoying this easy unit test configuration (and wondering why no-one has written “Learn … through Test Driven Development” books).
There are still rough edges I would like to iron out of this, but as a learning environment it’s fairly quick and easy.