在Clojure中如何定义一个可以从其他命名空间访问的全局变量

gec*_*chu 7 clojure

在clojure中,声明全局变量的最佳方法是什么,需要在函数中更改其值,并且需要在其他命名空间中访问该全局变量

前任:

(ns ..main
 .....) 

(def global_variable nil)
..
(defn main ...

Change the value of global variable here 

) 

Another name space 

 (ns accessvariable ...) 

 (println (main/global_variable))
Run Code Online (Sandbox Code Playgroud)

做这个的最好方式是什么?

Dan*_*ero 5

只需在您的全局变量中存储一个原子:

(def global-var (atom nil))
Run Code Online (Sandbox Code Playgroud)