Light Tableで
Clojure入門
ニャンパス株式会社 登尾(@tnoborio)
やること
Clojureとは
Light Tableのセットアップ
Leiningenのセットアップ
InstaReplでREPL
ウェブアプリケーション
Clojureとは
今一番イケている関数型言語
イケてる4つの理由
1) 関数型言語
2) マクロ!
3) JVM上で動作する
4) Javaのライブラリが使える
前は環境構築の壁があったけど、
今はLight Tableがあるから大丈夫!
ダウンロード
http://www.lighttable.com/
Light Table
Light Tableの使い方
Workspace Commands
Workspaceの表示
● Control + SpaceでCommands
● Commandsを出して、
“Toggle workspace tree”を選択
→Workspaceが左ペインに表示
Clojureプラグインのアップデート
1. Commandsで、”Plugins: Show plugin
manager”
2. Commandsで、”Plugins: Refresh plugin list”
3. Clojureプラグインのアップデート
4. 念のためLight Table再起動
Light TableでREPL
Commandsから”Instarepl: Open a clojure
instarepl”
● (+ 1 2 3)
● (println “Hello”)
Instareplでの標準出力
標準出力は、
Commands→“Console: Toggle console”
コードを打ってみよう!
(+ 1 2)
(+ 1 2 3 4)
(+)
コードを打ってみよう!
(println “Hello Clojure!”)
コードを打ってみよう!
(defn inc3 [a] (+ a 3))
(inc3 10)
Leiningenのインストール
1. http://leiningen.org/
からleinをダウンロードする。
2. パスの通ったディレクトリに置く
3. 実行権限の付与
Leiningenのインストール
Macの場合
$ curl -OL http://github.
com/technomancy/leiningen/raw/stable/bin/lein
$ mkdir ~/bin/
$ mv lein ~/bin/
$ chmod a+x ~/bin/lein
Leiningenのインストール
Windowsの場合
(@shinseitaroさんありがとうございます。)
lein.batをダウンロード
(もしくはInstallerもこちら)
lein.batを適当なディレクトリに置く
そのディレクトリを環境変数にセット http://next.matrix.
jp/config-path-win7.html
lein self-install
Leiningenでプロジェクト作成
lein new <プロジェクト名>
作ってみよう!
lein new sample
Light Tableからコードを触ってみる
Commandsで、”Add connection”を選び
Clojureを選択し、project.cljを選択
接続
Commands→”Add folder”で
Workspaceにsampleディレクトリを追加
src/sample/core.cljを開く
Commands→”Instarepl: Make current editor an
instarepl
接続のリスト
Commands→”Connect: Show connect bar”
“disconnect”で接続を切る
ウェブアプリケーション
テンプレートを使ったプロジェクト作成
lein new reloadable-compojure web
先程と同様に接続
Commands→”Connect: Add Connection”でproject.cljを指定
src/web/core.cljを開く
Commands→”Instarepl: Make current editor an instarepl
;; (start-server!)のコメントアウトを外す
ディレクトリ構造
● src/
● src/web/core.clj
● src/web/handler.clj
● project.clj
● test/
handler.clj(1)
(defroutes app-routes
(GET "/" [] "Hello World")
(route/resources "/")
(route/not-found "Not Found"))
handler.clj(2)
(def app
(-> app-routes
handler/site
(wrap-reload '(hoge.core))
(wrap-stacktrace)))

「はじめてのClojure」出版記念!Light Tableを使ってClojureに触れてみよう!