LoginSignup
6
5

More than 5 years have passed since last update.

プロジェクトを作らずにClojureライブラリをREPLで試す

Last updated at Posted at 2014-12-25

ライブラリをREPLにロードして動作を確かめたい、という時に、lein newでプロジェクトを作ってから、project.cljを編集するという手順を踏むことなく、いきなりREPLを起動する方法です。

lein-tryをLeiningenに登録

~/.lein/profiles.cljの:pluginsに[lein-try "0.4.3"]を追加します。

{:user {:plugins [[lein-try "0.4.3"]]}}

REPLを起動

project.cljの存在しないディレクトリでも、lein try com.taonsso/timbre "3.3.1"のようにライブラリを指定することで、Replにロードされます。バージョン名を省略すれば、最新版を取得してきます。

$lein try com.taoensso/timbre
Retrieving com/taoensso/timbre/3.3.1-1cd4b70/timbre-3.3.1-1cd4b70.pom from clojars
Retrieving com/taoensso/encore/1.8.1/encore-1.8.1.pom from clojars
Retrieving io/aviso/pretty/0.1.12/pretty-0.1.12.pom from clojars
Retrieving com/taoensso/timbre/3.3.1-1cd4b70/timbre-3.3.1-1cd4b70.jar from clojars
Retrieving com/taoensso/encore/1.8.1/encore-1.8.1.jar from clojars
Retrieving io/aviso/pretty/0.1.12/pretty-0.1.12.jar from clojars
nREPL server started on port 64783 on host 127.0.0.1 - nrepl://127.0.0.1:64783
REPL-y 0.3.5, nREPL 0.2.6
Clojure 1.6.0
Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-466.1-11M4716
    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

user=> (ns my-app (:require [taoensso.timbre :as timbre]))
nil
my-app=> (timbre/refer-timbre)
nil
my-app=> (info "test")
2014-Dec-24 21:56:32 -0800 mba.local INFO [my-app] - test
nil
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5