gpt4 book ai didi

clojure - 如何在启动repl时默认加载ns

转载 作者:行者123 更新时间:2023-12-02 09:13:20 24 4
gpt4 key购买 nike

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

最佳答案

您会在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=>

关于clojure - 如何在启动repl时默认加载ns,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12329713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com