Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. boot.user=> (binding [*out* (java.io.StringWriter.)] (println "hello") (str *out*))
  2. "hello\r\n"
  3. boot.user=> (source with-out-str)
  4. (defmacro with-out-str
  5.   "Evaluates exprs in a context in which *out* is bound to a fresh
  6.  StringWriter.  Returns the string created by any nested printing
  7.  calls."
  8.   {:added "1.0"}
  9.   [& body]
  10.   `(let [s# (new java.io.StringWriter)]
  11.      (binding [*out* s#]
  12.        ~@body
  13.        (str s#))))
  14. nil
  15. boot.user=> (with-out-str (println "hello"))
  16. "hello\r\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement