【发布时间】:2019-12-23 09:06:53
【问题描述】:
(ns secretary.core)
(defn -main
[& args]
(println args "Hello, World!"))
lein 运行 1 2 3
(1 2 3) 你好,世界!
但我希望它保留在 REPL 中。不退出。
【问题讨论】:
(ns secretary.core)
(defn -main
[& args]
(println args "Hello, World!"))
(1 2 3) 你好,世界!
但我希望它保留在 REPL 中。不退出。
【问题讨论】:
试试这个:
(ns demo.core )
(defn -main
[& args]
(println "Got:" args ))
上面的代码:
> lein repl
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
Compiling 2 source files to /home/alan/expr/demo/target/default/class-files
nREPL server started on port 46184 on host 127.0.0.1 - nrepl://127.0.0.1:46184
REPL-y 0.4.3, nREPL 0.6.0
Clojure 1.10.1
Java HotSpot(TM) 64-Bit Server VM 13+33
demo.core=> (ns demo.core)
nil
demo.core=> (-main 1 2 3)
Got: (1 2 3)
demo.core=> (+ 3 4)
7
demo.core=>
所以,你首先启动 REPL,然后调用一个函数(甚至是 -main)。完成后你仍在 REPL 中。
附:虽然,我个人最喜欢的是使用lein test-refresh 插件并使用您喜欢的编辑器以单元测试风格编写您的实验。
【讨论】:
-main 的参数是像在执行lein run 1 2 3 时一样的字符串,您可以在REPL 中调用(-main "1" "2" "3"),但这是一个细节。跨度>