Skip to content

Commit

Permalink
Added doc string to ns macro, patch from mb
Browse files Browse the repository at this point in the history
  • Loading branch information
richhickey committed Jan 23, 2009
1 parent 92a2a04 commit 21caa3e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/clj/clojure/core.clj
Expand Up @@ -2762,6 +2762,13 @@
(println type)
(println (str " Please see http://clojure.org/special_forms#" anchor)))

(defn print-namespace-doc
"Print the documentation string of a Namespace."
[nspace]
(println "-------------------------")
(println (str (ns-name nspace)))
(println " " (:doc ^nspace)))

(defmacro doc
"Prints documentation for a var or special form given its name"
[name]
Expand All @@ -2771,7 +2778,10 @@
(syntax-symbol-anchor `~name)
`(print-special-doc '~name "Syntax Symbol" (syntax-symbol-anchor '~name))
:else
`(print-doc (var ~name))))
(let [nspace (find-ns name)]
(if nspace
`(print-namespace-doc ~nspace)
`(print-doc (var ~name))))))

(defn tree-seq
"returns a lazy sequence of the nodes in a tree, via a depth-first walk.
Expand Down Expand Up @@ -3319,6 +3329,12 @@
(fn [[kname & args]]
`(~(symbol "clojure.core" (clojure.core/name kname))
~@(map #(list 'quote %) args)))
docstring (when (string? (first references)) (first references))
references (if docstring (rest references) references)
name (if docstring
(with-meta name (assoc (meta name)
:doc docstring))
name)
gen-class-clause (first (filter #(= :gen-class (first %)) references))
gen-class-call
(when gen-class-clause
Expand Down Expand Up @@ -3789,7 +3805,7 @@
~(emit gpred gexpr clauses))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; helper files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(alter-meta! (find-ns 'clojure.core) assoc :doc "Fundamental library of the Clojure language")
(load "core_proxy")
(load "core_print")
(load "genclass")
Expand Down
3 changes: 2 additions & 1 deletion src/jvm/clojure/lang/Namespace.java
Expand Up @@ -27,6 +27,7 @@ public String toString(){
}

Namespace(Symbol name){
super(name.meta());
this.name = name;
mappings.set(RT.DEFAULT_IMPORTS);
aliases.set(RT.map());
Expand Down Expand Up @@ -174,4 +175,4 @@ public void removeAlias(Symbol alias) throws Exception{
map = getAliases();
}
}
}
}

0 comments on commit 21caa3e

Please sign in to comment.