   ^{:author "Stuart Sierra",
      :doc "Search for ns declarations in dirs, JARs, or CLASSPATH"} 
   clojure.tools.namespace
-  (:require [clojure.java.classpath :as classpath])
+  (:require [clojure.java.classpath :as classpath]
+            [clojure.set :as set])
   (import (java.io File FileReader BufferedReader PushbackReader
                    InputStreamReader)
           (java.util.jar JarFile)))

(defn- deps-from-ns-form [form]
  (when (and (list? form)
	     (contains? #{:use :require} (first form)))
    (apply union (map #(deps-from-libspec nil %) (rest form)))))

(defn deps-from-ns-decl
  "Given a (quoted) ns declaration, returns a set of symbols naming
  the dependencies of that namespace.  Handles :use and :require
  clauses but not :load."
  [decl]
  (apply union (map deps-from-ns-form decl)))

;;; Parsing dependencies

(defn- deps-from-libspec [prefix form]
  (cond (list? form) (apply set/union (map (fn [f] (deps-from-libspec
						(symbol (str (when prefix (str prefix "."))
							     (first form)))
						f))
