Error formatting macro: pagetree: java.lang.NullPointerException
Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version. Compare with Current  |   View Page History

The easiest way to get started writing Clojure code is with Clooj, an editor and IDE written entirely in Clojure itself.  It can be downloaded from here

Once you have it, you can run it by double-clicking (assuming you have Java installed).  Here is a screenshot, showing some of the source code for Clooj itself:

The left column is the file-browser window, where you choose different files and projects to work on.  The middle window is where code in files is edited.  The right column is called the "Read-Eval-Print Loop" (or REPL for short)----this is where you test code out as you're writing it.

When you first open Clooj, there will be nothing in these windows.  To get something, try going to Project -> New and creating a project for yourself.  You should see the files in it displayed in the file-browser window.  Click on the file under the 'src' directory in the new project (it should end with ".core").  You should now see a prompt in the top half of the REPL.  Try entering some code in the bottom half of the REPL, such as (+ 1 2).  You should be able to type Return and evaulate it, seeing the result in the top half of the REPL. 

You should now be able to enter any Clojure expression into Clooj you want and see what happens.  Use Clooj to work through examples as you're learning Clojure. 

Once you've gotten a couple of things entered into the REPL, notice that you can retrieve prior expressions by typing the up arrow key, and browse back to later ones with the down arrow key.  Also notice that Clooj checks your parentheses for you: if there is an unbalanced parenthesis, it is highlighted in light red.  Try typing (() or ()) to see this in action.

Once you're ready to write some longer code, enter it in one of the existing files (or choose File -> New to get a new one).  You can work with the file (sending it to the REPL) by choosing REPL -> Evaluate Entire File.  Once you do this, you should be able to use functions defined in that file at the REPL.

This is enough to get you started coding in Clojure.


Build tools:

Once you are comfortable writing and testing code in Clooj, check out the Getting Started with Leiningen guide.  Leiningen allows you to build and run projects from the command line, as well as get a REPL on the command line; you'll want to have it (or something equivalent) if you are doing any substantial project.  If you look at the project.clj file in your projects, you will see the format Leiningen uses to build programs.

You'll want to have Git installed, too.

Other Editors:

If you've already used Java, you might want to try out one of the plugins for your favorite IDE: Eclipse, Netbeans, or IntelliJ.  Many experienced Clojure developers, however, use Emacs.  If you can handle the learning curve and getting it configured for Clojure, you may find it very productive.

Things you can do with Clojure:

Once you have Leiningen, check out Noir if you want to build a website.  Incanter is a powerful package for doing statistics and charts.  This is only the beginning of what you can do with Clojure.