user1311390
user1311390

Reputation:

Clojure: Defining a symbol in another namespace

Context

This is the contents of init.clj

(ns init)

(defn get-hotswap []
  (filter #(= (ns-name %) 'hotswap) (all-ns)))

(let [x (get-hotswap)]
  (let [old-ns *ns*]
    (if (empty? x)
      (do
        (create-ns 'hotswap)
        (in-ns 'hotswap)
        (def global-kv-store (clojure.core/atom {}))
        (in-ns (ns-name old-ns)))
      (println "Found Hotswap"))))

Now. hotswap/global-kv-store does not exist, but init/global-kv-store does exist.

Question

How do I fix this? I want to be able to

Thanks!

Upvotes: 1

Views: 355

Answers (1)

ivant
ivant

Reputation: 3919

You can try this:

(if-not (find-ns 'hotswap)
  (intern (create-ns 'hotswap) 'global-kv-store (atom {})))

Upvotes: 1

Related Questions