2012-09-08 7 views

Respuesta

10

Usted encontrará una gran cantidad de respuestas en el 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*) 

El uso de un project.clj que habían útil:

(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"]]) 

Cuando el fuego de 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

Gracias @noahz. Quiero ser capaz de especificar lo siguiente donde las 3 instrucciones en el fn son lo que quiero ejecutar, ¿cómo hago eso?: Repl-options {: init (fn [_] (use 'ring.util.serve) (use 'mfaiz.routes) (serve mfaiz.routes/my-app))} – murtaza52

+1

Usted acaba de definir una función, así que agregue un segundo conjunto de paréntesis y el parámetro deseado para llamarlo. '((fn [_] (println _)" foo ")' – noahlz

+0

Lo hice y este es el error que me da - CompilerException java.lang.RuntimeException: no se puede resolver el símbolo: servir en este contexto, compilando: (NO_SOURCE_PATH: 1) – murtaza52

3

a veces uso la opción :injections en project.clj para cargar espacios de nombres. En el siguiente ejemplo se carga la foo.bar espacio de nombres cuando se ejecuta el comando lein2:

(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

Eso es lo que ': repl-options { : init expr} 'es para – noahlz

Cuestiones relacionadas