You're viewing version 1.2.0 of with-out-str. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

with-out-str

clojure.core

  • (with-out-str & body)
Evaluates exprs in a context in which *out* is bound to a fresh
StringWriter. Returns the string created by any nested printing
calls.

1 Example top

  • ;; Instead of printing the following will place the output normally
    ;; sent to standard out to a string.
    user=> (with-out-str (println "this should return as a string"))
    "this should return as a string\n"
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:3674 top

(defmacro with-out-str
  "Evaluates exprs in a context in which *out* is bound to a fresh
  StringWriter.  Returns the string created by any nested printing
  calls."
  {:added "1.0"}
  [& body]
  `(let [s# (new java.io.StringWriter)]
     (binding [*out* s#]
       ~@body
       (str s#))))
Vars in clojure.core/with-out-str: defmacro *out* apply binding concat let list seq str vector

Comments top

No comments for with-out-str. Log in to add a comment.