如何在启动repl时默认加载ns [英] how to load ns by default when starting repl

查看:114
本文介绍了如何在启动repl时默认加载ns的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用lein2。我想加载一些ns默认情况下,当repl开始。是否可以在project.clj中指定应该加载的ns,当对该项目执行lein2 repl时?

I am using lein2. I would like to load some ns by default when the repl starts. Is it possible to either specify in project.clj the ns that should be loaded, when lein2 repl is executed for that 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=>

这篇关于如何在启动repl时默认加载ns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆