2012-09-08 19 views

回答

10

你會發現很多答案在sample project

;; Options to change the way the REPL behaves 
:repl-options {;; Specify the string to print when prompting for input. 
       ;; defaults to something like (fn [ns] (str *ns* "=> ")) 
       :prompt (fn [ns] (str "your command for <" ns ">, master? ")) 
       ;; Specify the ns to start the REPL in (overrides :main in 
       ;; this case only) 
       :init-ns foo.bar 
       ;; This expression will run when first opening a REPL, in the 
       ;; namespace from :init-ns or :main if specified 
       ;; This expression will run when first opening a REPL, in the 
       ;; namespace from :init-ns or :main if specified 
       :init (println "here we are in" *ns*) 

使用project.clj我已經得心應手:

(defproject test "1.0.0" 
    :repl-options { :init-ns test.core 
        :init (do 
          (use 'clojure.set) 
          (println (union #{1 2 3} #{3 4 5})) 
          (use 'incanter.core) 
          (println (factorial 5))) } 
    :dependencies [[org.clojure/clojure "1.4.0"] 
       [incanter/incanter-core "1.3.0-SNAPSHOT"]]) 

當我火了lein repl

$ lein repl 
nREPL server started on port 1121 
REPL-y 0.1.0-beta10 
Clojure 1.4.0 
    Exit: Control+D or (exit) or (quit) 
Commands: (user/help) 
    Docs: (doc function-name-here) 
      (find-doc "part-of-name-here") 
    Source: (source function-name-here) 
      (user/sourcery function-name-here) 
Javadoc: (javadoc java-object-or-class-here) 
Examples from clojuredocs.org: [clojuredocs or cdoc] 
     (user/clojuredocs name-here) 
     (user/clojuredocs "ns-here" "name-here") 
#{1 2 3 4 5} 
120.0 
test.core=> 
+0

由於@noahz。我希望能夠在fn中的3個語句是我想執行的地方指定以下內容,我該怎麼做 - :repl-options {:init(fn [_](use'ring.util.serve) (使用'mfaiz.routes) (serve mfaiz.routes/my-app))} – murtaza52

+1

你只是定義一個函數,所以添加第二組括號和所需的參數來調用它。 '((fn [_](println _)「foo」)' – noahlz

+0

這是否是這樣的錯誤?CompilerException java.lang.RuntimeException:無法解析符號:在此上下文中編譯:(NO_SOURCE_PATH: 1) – murtaza52

3

我有時用中的:injections選項 加載名稱空間。執行lein2命令時,以下示例將加載 foo.bar名稱空間:

(defproject org.example/sample "0.1.0-SNAPSHOT" 
    :description "A sample project" 
    :url "http://example.com/FIXME" 
    :license {:name "Eclipse Public License" 
      :url "http://www.eclipse.org/legal/epl-v10.html"} 
    :injections [(use 'foo.bar)]) 
+1

這就是':repl-options { :init expr'是for – noahlz

相關問題