Getting Started

Setup

Clojure is hosted on SourceForge.


Feedback and discussion should occur on the Clojure Google Group. Please join us!


Community-supplied supplementary material and tips are on the Wiki. Feel free to contribute your expertise.


Clojure is delivered in a zip file containing a single .jar, clojure.jar, a readme, the CPL license and the source code in a src subdirectory. It uses the ASM 3.0 bytecode library, and the current alpha distribution includes it. Java 1.5 or greater is required.

Quick Start

In the directory in which you expanded clojure.zip, run:


java -cp clojure.jar clojure.lang.Repl

This will bring up a simple read-eval-print loop (REPL). Much of Clojure is defined in Clojure itself (in the boot.clj file included in the src directory of distribution), which is automatically loaded from the .jar file when Clojure starts.


When boot.clj is loaded you will have the language as described herein fully available.

Try:


user=> (+ 1 2 3)
6
user=> (. javax.swing.JOptionPane (showMessageDialog nil "Hello World"))    

The REPL has very rudimentary editing. For a better experience, try running it via the JLine ConsoleRunner:

java -cp jline-0.9.91.jar:clojure.jar jline.ConsoleRunner clojure.lang.Repl
 

This will give you left/right arrow key navigation and up/down arrow command history.

Editing

Editing of Clojure code is greatly facilitated by using an editor that has parens-matching. Lennart Staflin has provided a Clojure mode for Emacs, which provides syntax highlighting, parens matching, and the ability to run Clojure in a secondary process and send code to be evaluated from the editor, and Jeffrey Chu has provided an enhanced Clojure mode for Emacs. Toralf Wittner has supplied a syntax file for VIM. Eric Thorsen and company are building enclojure, a Netbeans plugin for Clojure. Thanks to all!

Debugging

I have had success debugging Clojure code with JSwat, specifically, version 3.16 on Mac OS X. You can start Clojure under JSwat, but with limited input capabilities. Better is to attach JSwat to a running instance of Clojure. You have to start Java with these flags to support remote debugging:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n

When Clojure starts it will print something like:

Listening for transport dt_socket at address: 63657 
Clojure 
user=>

Then in JSwat choose Attach... and put localhost for Host and the socket address for Port. In JSwat, open up some Clojure file you have loaded, (including boot.clj) and you can set breakpoints in Clojure source. Breakpoints, call stack, local variable views and step debugging (within Clojure code and from Clojure to Java and back) all work. You can also attach to Clojure when it is started as the inferior Lisp in Emacs. Best of all, if you change a .clj file and reload it, JSwat will pick up the changed file and you can set breakpoints etc in the new code without stopping and restarting JSwat or Clojure.

Copyright © Rich Hickey