Getting Started With Clojure On a Mac
The resources and tools I recommend.
Please note that this post has been written in early 2014. I am currently not writing any Clojure and this post won’t be updated.
Clojure is a very interesting, relatively new programming language. This is not an introduction to Clojure, just a write-down of which tools and resources I ended up using — intended to quickly set you up to be ready to play around with and learn Clojure on your Mac.
Installation
First you should get the current Java SE JDK (not JRE) from Oracle. You can download it here. You should now be able to issue:
javac -version
and get a plausible response.
If you are on a Mac and doing any sort of software development you are probably using homebrew. if that’s the case then you can simply install Clojure using:
brew install leiningen
Leiningen is the project management / build tool / dependency resolution tool that almost everybody uses in the Clojure ecosystem. It installs Clojure itself as a dependency.
You can check the installation by issuing
lein help
It’s normal that this is slow, don’t worry about it (it dynamically generates the help options from inspecting your environment).
To get a repl, the interactive environment that is at the heart of Clojure development, issue:
lein repl
Now you could start playing around with Clojure.
Editor
When you do Clojure development you usually use an editor with repl integration. This means you have one section of the screen or window dedicated to code editing, and in the other section you try out the code you write. This is very essential to Clojure development, and you should not try to do without it in my opinion. Most hardcore Clojure people seem to use emacs, but I did not want to add this to the pile of things I had to learn. I want to name three other options I did not end up using, without much commentary:
- LightTable
- Counterclockwise (Eclipse Plugin)
- La Clojure (IntelliJ Plugin)
What I ended up using is Sublime Text 2 with the SublimeRepl plugin. I think this is an interesting option if you are already using Sublime Text.
Here’s what you need to do:
- Install Package Control in SublimeText
- Install SublimeRepl via Package Control
- Start a a ClojureRepl via the Command Palette
Now you can start using the repl — you will need the buffer shortcuts to properly do so.
A bug in SublimeRepl
There’s a bug in the Sublime repl which makes it so that backslashes are not properly escaped when sent to the repl. The bug is already fixed in master, but not in the current release 2.1.1.
You can check the discussion here. To fix the issue I manually patched a Python file which you can probably find here on your Mac:
~/Library/Application Support/Sublime Text 2/Packages/SublimeREPL
Although for me the SublimeRepl Package was strangely in the folder for Sublime Text 3.
You can now patch the file as per this pull request: https://github.com/wuub/SublimeREPL/pull/293/files
Alternatively just install the package manually from the Git Master.
Resources
I checked both the books Clojure Programming and Programming Clojure and I personally thought that Programming Clojure was by far the best resource, looking at both books and online stuff. I recommend buying this book.
For reference purposes I think the Clojure website is not very good and the docs are very concise but can be underwhelmingly explanatory if you are not a functional programming expert. You get somewhat used to the docs though.
You should look at the docs from the Clojure repl directly, like so:
(doc +)
You can also call get Javadocs directly from the repl, e. g. using:
(javadoc String)