【发布时间】:2020-09-26 11:29:47
【问题描述】:
我正在尝试获取与实际运行的代码关联的命名空间。
我使用“lein new app test”创建了一个模板项目:
(ns test.core
(:gen-class))
(defn -main
[& args]
(println (ns-name *ns*)))
使用 repl 时,*ns* 计算结果为 test.core:
echo "(-main)" | lein repl
nREPL server started on port 37435 on host 127.0.0.1 - nrepl://127.0.0.1:37435
REPL-y 0.4.4, nREPL 0.7.0
Clojure 1.10.1
OpenJDK 64-Bit Server VM 1.8.0_265-b01
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Javadoc: (javadoc java-object-or-class-here)
Exit: Control+D or (exit) or (quit)
Results: Stored in vars *1, *2, *3, an exception in *e
test.core=> (-main)
test.core
nil
test.core=> Bye for now!
但是当使用 lein run 时,我得到了用户命名空间:
lein run
user
为什么会有这样的行为? 如何获取 repl 中的一段代码的命名空间?
【问题讨论】:
-
你可能会觉得这个问题也很有趣:stackoverflow.com/questions/56102766/…
标签: clojure