Skip to content

Instantly share code, notes, and snippets.

@ivermac
Last active November 23, 2019 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivermac/dd25bc4fe9297c337d384183d968ca3e to your computer and use it in GitHub Desktop.
Save ivermac/dd25bc4fe9297c337d384183d968ca3e to your computer and use it in GitHub Desktop.
Load and check if a namespace exists
(defn namespace-exists?
  "check that a namespace has been loaded"
  [str-val]
  (-> str-val
      symbol
      find-ns
      nil?
      not))
      
(defn file-path->str-namespace
  "replace slashes with dots"
  [file-path]
  (-> file-path
      (subs 1)
      (clojure.string/replace #"/" ".")))
      
 (defn load-and-check
   "file located at src/<file-path>. <file-path> is a string"
   [file-path]
   (let [file-namespace (file-path->str-namespace file-path)]
     (load file-path)
     (namespace-exists? file-namespace))
     
 ;; Assuming `random-file.clj` is in src/
 (load-and-check "random-file.clj")
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment