clojure - How do I use with-out-str with collections? -


i can use with-out-str string value (doc func).

=> (with-out-str (doc first)) "-------------------------\nclojure.core/first\n([coll])\n  returns first item in collection. calls seq on its\n    argument. if coll nil, returns nil.\n"     

however, if try same thing collection of functions, can return empty string each:

=> (map #(with-out-str (doc %)) [first rest]) ("" "") 

where going wrong here?

unfortunately doc macro, , such not first class citizen in clojure because cannot use higher order function.

user> (doc doc) ------------------------- clojure.repl/doc ([name]) macro   prints documentation var or special form given name  

what seeing output of looking documentation % twice.

user> (doc %) nil  user> (with-out-str (doc %)) "" 

because call doc has finished running during macro-expansion-time, before call map runs (at run-time). can doc string directly metadata on var containing functions

user> (map #(:doc (meta (resolve %))) '[first rest]) ("returns first item in collection. calls seq on its\n    argument. if coll nil, returns nil."   "returns possibly empty seq of items after first. calls seq on its\n  argument.") 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -