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 is very new, but already has enough functionality to get started with Clojure (and more is being added rapidly).  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.

Labels: