Getting started with Clojure

The LJC book club is moving on to the book Functional Programming for the Object Orientated Programmer.

The easiest way to get going with Clojure on a mac is with home brew:

brew install clojure

This gives you the clj command which launches a REPL where you can do the customary hello world:

Leiningen is a useful tool for creating Clojure projects; it is also available with home brew:

brew install leiningen

Creating a clojure project with leiningen is as easy as:

lein new oobook-lein

There is a clojure plugin and a leiningen plugin for Intellij that'll make your life much easier. Just go to plugins and search Clojure and Leiningen from the Settings -> Plugins -> Brouse Repositories. Once you have done this you can open your leiningen project in Intellij and you get an environment like this:

The integration with IntelliJ is really nice.

To open up a REPL to play with: Tools -> Start Clojure Console
To load the current clojure script into the REPL so you can use anything you've defined: Tools -> Clojure REPL -> Load files to REPL

To test your setup you can use the hello world example:

And then load it into your REPL then execute the following:
And you should get the output like in the IntelliJ screenshot!