読者です 読者をやめる 読者になる 読者になる

DELAEMON BLOG

Live as if you were to die tomorrow. Learn as if you were to live forever.

Clojure Leiningen

Clojureことはじめ

"Leiningen is the easiest way to use Clojure. With a focus on project automation and declarative configuration, it gets out of your way and lets you focus on your code."
Leiningen

leiningen をインストール

$ brew install leiningen

プロジェクトを作成

$ lein new hello

ディレクトリ構成は以下

$ tree
.
├── CHANGELOG.md
├── LICENSE
├── README.md
├── dev-resources
├── doc
│   └── intro.md
├── project.clj
├── resources
├── src
│   └── hello
│       └── core.clj
├── target
│   ├── classes
│   │   └── META-INF
│   │       └── maven
│   │           └── hello
│   │               └── hello
│   │                   └── pom.properties
│   └── stale
│       └── extract-native.dependencies
└── test
    └── hello
        └── core_test.clj

14 directories, 9 files

project.cljを書き換え

cat project.clj
(defproject hello "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.7.0"]]
  :main hello.core)


lein repl で 実行。lein --help すると "Start a repl session either with the current project or standalone."

$ lein repl
nREPL server started on port 52522 on host 127.0.0.1 - nrepl://127.0.0.1:52522
REPL-y 0.3.7, nREPL 0.2.10
Clojure 1.7.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_65-b17
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

hello.core=> fo #Tabで候補が表示される
foo      for      force    format
hello.core=> (foo "delaemon")
delaemon Hello, World!
nil