previous up next contents
Previous: 目次 Up: Clojureリファレンス Next: 2 The Reader

Subsections


1 さぁ始めよう / Getting Started

1.1 準備 / Setup

ClojureはGoogle Codeでホストされており、ソース・レポジトリはGitHubにある。他にもCLRへのポートがある。Assemblaで開発の協力体制がしかれている。

フィードバックや議論はClojure Google Groupで行われているので、ぜひ参加して欲しい。

コミュニティによるツールやヒントはWiki上で展開されている。こちらにも積極的に参加して、知見を共有してほしい。

Clojureはclojure.jar、ドキュメント、ソースコードが入ったzipファイルとして配布されている。Clojureで使用されているASM 3.0バイトコード・ライブラリも配布物に含まれている。なお、Javaはバージョン1.5以上が必要になる。

1.2 Quick Start

clojure.zipを展開したディレクトリ内で
java -cp clojure.jar clojure.main
と入力すると、シンプルなread-eval-print-loop (REPL)がはじまる。Clojureの大部分はClojure自身で書かれており (srcディレクトリ内のcore.cljがそれだ)、Clojureの起動時に自動的にjarファイルから読み込まれる。クラスパスにuser.cljが見つかったら、これも自動的に読み込まれるので、ユーザーがClojure起動時に自動実行させたいものはここに書いておくと良いだろう。

When core.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.main
This will give you left/right arrow key navigation and up/down arrow command history.

1.3 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. There is also La Clojure, a Clojure plugin for IntelliJ IDEA, and Counterclockwise, a Clojure plugin for Eclipse. Thanks to all!

1.4 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:
java -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.

1.5 Profiling

Profiling of Clojure code should be possible with any Java profiler. I've had success with the YourKit Java Profiler, licenses for which were generously donated by YourKit.

YourKit is kindly supporting open source projects with its full-featured Java Profiler. YourKit, LLC is the creator of innovative and intelligent tools for profiling Java and .NET applications. Take a look at YourKit's leading software products: YourKit Java Profiler and YourKit .NET Profiler.


previous up next contents
Previous: 目次 Up: Clojureリファレンス Next: 2 The Reader
MARUI Atsushi
2013-01-12