我想知道为什么会这样。
finally
和&
也以这种方式行事。
哪个其他Clojure符号有这种行为?为什么?
答案 0 :(得分:7)
我相信你偶然发现了Clojure实施doc
中影响&
,catch
和finally
的错误。在当前的doc
实现中,这三个被特别处理,并且关联的表达式似乎缺少语法引用。
以下是一个mod to doc,它添加了语法引用并且似乎按预期工作。此函数必须放在clojure.repl
命名空间中。
(defmacro doc2
[name]
(if-let [special-name ('{& fn, catch try, finally, try} name)]
`(#'print-doc (#'special-doc '~special-name))
(cond
(special-doc-map name) `(#'print-doc (#'special-doc '~name))
(find-ns name) `(#'print-doc (#'namespace-doc (find-ns '~name)))
(resolve name) `(#'print-doc (meta (var ~name))))))
(doc catch)
=> {prints try
doc并返回nil}
(doc2 catch)
=> {prints try
doc并返回nil}
(with-out-str (doc catch))
=> {打印try
doc并返回""
}
(with-out-str (doc2 catch))
=> "-------------------------\ntry\n (try expr* catch-clause* finally-clause?)\nSpecial Form\n catch-clause => (catch classname name expr*)\n finally-clause => (finally expr*)\n\n Catches and handles Java exceptions.\n\n Please see http://clojure.org/special_forms#try\n"
我会在Clojure bug追踪器上追逐它。