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

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

问题描述

我正在使用 lein2.我想在 repl 启动时默认加载一些 ns.当为该项目执行 lein2 repl 时,是否可以在 project.clj 中指定应该加载的 ns?

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天全站免登陆