First steps with Clojure

Over the last year, I learned Ruby. I’m not amazing at it and there’s still a lot to learn, but I know enough to be useful with it. In the spirit of learning a new language every year, the next one I wanted to tackle was Clojure.

I also decided to try using Emacs, since I had heard the Clojure support was pretty good.

After installing Emacs on my Mac (which is running OS X 10.7), I spent the morning surfing teh interwebz and trying a few different things to get Clojure working. Here’s how it looked in the end:

  1. Install Emacs from here.
  2. Read the tutorial to understand the basic shortcuts (C = control, M = alt below)
  3. Install marmalade – inside the directory ~/.emacs.d create the file init.el and enter:

    (require 'package)
    (add-to-list 'package-archives
    '("marmalade" . "http://marmalade-repo.org/packages/") t)
    (package-initialize)

  4. Run M-x: “package-refresh-contents”
  5. M-x package-install starter-kit
  6. Install clojure-mode by pressing M-x package-install and choose clojure-mode.
  7. Install Leiningen by folling the instructions here: https://github.com/technomancy/leiningen
  8. Install swank-clojure: run “lein plugin install swank-clojure 1.3.3”
    Note – I initially installed 1.3.2 which gave me an error when I tried to run it from Emacs.
  9. Create a new project with Leiningen.
  10. Open Emacs, navigate to a project file and type M-x clojure-jack-in.

Once this was working, I also discovered a couple of key shortcuts that were really useful:

  • C-c C-k compiles the code in the current buffer.
  • C-x C-e executes the code in the buffer before the current line end.

Now I’m up and running, I’ve been able to complete all of the 4Clojure Koans at the elementary level. You don’t actually need to have clojure running locally, although I found it helped to figure out what was going on.

I’m also working on the Clojure Koans on github.

So far I’m finding both to be really fun and good learning resources ☺

Some of the best guidance I found

4 thoughts on “First steps with Clojure

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>