如何打印所需的命名空间?

rus*_*ter 0 clojure

我需要命名空间,我可以使用它:

(ns core
  (:require [hello :as h]))

(println h/x)
Run Code Online (Sandbox Code Playgroud)

但为什么我不能只打印名称空间?

(println h) # Unable to resolve symbol: h in this context 
Run Code Online (Sandbox Code Playgroud)

我用 deps-tools 和 leiningen 尝试过这个

Jam*_*ott 5

当您说(println h)您要求打印绑定到h当前命名空间中的符号的值时。h除非后面跟有字符,否则不会被解释为命名空间(或命名空间别名)/。因此要求打印绑定到别名引用的命名空间中的(println h/x)符号的值,换句话说,。您尚未将任何内容绑定到命名空间中的符号,因此其本身是未定义的。xhhello.xhh

如果您想查看名称空间本身,请执行类似的操作(println (the-ns 'hello))(请参阅https://clojuredocs.org/clojure.core/the-ns)。