On Mar 22, 10:34 am, Mark Volkmann wrote:
> (defn get-output [fn]
> (let [sw (StringWriter.)]
> (binding [*out* sw] (fn))
> (.toString sw)))
This is what clojure.core/with-out-str does.
-Stuart Sierra
--~--~-~--~~~---~--~~
You received this message beca
Never mind. I think I needed to make this a macro instead of a
function like this:
(defmacro get-output [fn]
`(let [sw# (StringWriter.)]
(binding [*out* sw#] ~fn)
(.toString sw#)))
On Mar 22, 9:34 am, Mark Volkmann wrote:
> I can't figure out why this function seems to work, but also
I can't figure out why this function seems to work, but also produces
a NullPointerException.
(defn get-output [fn]
(let [sw (StringWriter.)]
(binding [*out* sw] (fn))
(.toString sw)))
(get-output (println "foo"))
--
R. Mark Volkmann
Object Computing, Inc.
--~--~-~--~~--