ok, với sự giúp đỡ của anh chàng này, Michael Kohl, tôi phát hiện ra làm thế nào để chuyển sang một không gian tên được tổ chức tại một biến (read here for more details)
như vậy, ở đây chúng tôi đi:
user=> (def working-namespace (create-ns 'my-namespace))
#'user/working-namespace
user=> (in-ns (symbol (str working-namespace)))
#<Namespace my-namespace>
my-namespace=>
;; notice how it switched to "my-namespace"
;; now if i were to put some other namespace in that variable...
my-namespace=> (ns user)
nil
user=> (def working-namespace (create-ns 'other-namespace))
#'user/working-namespace
;; and switch again, i would get the new namespace
user=> (in-ns (symbol (str working-namespace)))
#<Namespace other-namespace>
other-namespace=> ; tadaa!
mặc dù tôi không nghĩ rằng đó là clojure thành ngữ gán biến, bạn có thể xây dựng này thành một chức năng mà được các var giữ cho không gian tên như tham số
ngay để có được giá trị của một var bên trong và bên ngoài mà namespace
user=> (intern working-namespace 'some-var "my value")
#'other-namespace/some-var
user=> (var-get (intern working-namespace 'some-var))
"my value"
Nhưng một cái gì đó dọc theo dòng (defmacro defns-name [name] '(def ~ name (ns-name * ns *))) và sau đó gọi (defns-name namespace-name) sẽ hoạt động. –
Markdown ăn các ngôi sao xung quanh 'ns' trong Nicolas bình luận ở trên: nên đọc:' (defmacro defns-name [name] \ '(def ~ tên (ns-name * ns *)))'. –