(write object & kw-args)
Write an object subject to the current bindings of the printer control variables.
Use the kw-args argument to override individual variables for this call (and any
recursive calls). Returns the string result if :stream is nil or nil otherwise.
The following keyword arguments can be passed with values:
Keyword Meaning Default value
:stream Writer for output or nil true (indicates *out*)
:base Base to use for writing rationals Current value of *print-base*
:circle* If true, mark circular structures Current value of *print-circle*
:length Maximum elements to show in sublists Current value of *print-length*
:level Maximum depth Current value of *print-level*
:lines* Maximum lines of output Current value of *print-lines*
:miser-width Width to enter miser mode Current value of *print-miser-width*
:dispatch The pretty print dispatch function Current value of *print-pprint-dispatch*
:pretty If true, do pretty printing Current value of *print-pretty*
:radix If true, prepend a radix specifier Current value of *print-radix*
:readably* If true, print readably Current value of *print-readably*
:right-margin The column for the right margin Current value of *print-right-margin*
:suppress-namespaces If true, no namespaces in symbols Current value of *print-suppress-namespaces*
* = not yet supported
Source
(defn
write
"Write an object subject to the current bindings of the printer control variables.\nUse the kw-args argument to override individual variables for this call (and any\nrecursive calls). Returns the string result if :stream is nil or nil otherwise.\n\nThe following keyword arguments can be passed with values:\n Keyword Meaning Default value\n :stream Writer for output or nil true (indicates *out*)\n :base Base to use for writing rationals Current value of *print-base*\n :circle* If true, mark circular structures Current value of *print-circle*\n :length Maximum elements to show in sublists Current value of *print-length*\n :level Maximum depth Current value of *print-level*\n :lines* Maximum lines of output Current value of *print-lines*\n :miser-width Width to enter miser mode Current value of *print-miser-width*\n :dispatch The pretty print dispatch function Current value of *print-pprint-dispatch*\n :pretty If true, do pretty printing Current value of *print-pretty*\n :radix If true, prepend a radix specifier Current value of *print-radix*\n :readably* If true, print readably Current value of *print-readably*\n :right-margin The column for the right margin Current value of *print-right-margin*\n :suppress-namespaces If true, no namespaces in symbols Current value of *print-suppress-namespaces*\n\n * = not yet supported\n"
[object & kw-args]
(let
[options (merge {:stream true} (apply hash-map kw-args))]
(binding
[cljs.pprint/*print-base*
(:base options cljs.pprint/*print-base*)
cljs.pprint/*print-circle*
(:circle options cljs.pprint/*print-circle*)
cljs.core/*print-length*
(:length options cljs.core/*print-length*)
cljs.core/*print-level*
(:level options cljs.core/*print-level*)
cljs.pprint/*print-lines*
(:lines options cljs.pprint/*print-lines*)
cljs.pprint/*print-miser-width*
(:miser-width options cljs.pprint/*print-miser-width*)
cljs.pprint/*print-pprint-dispatch*
(:dispatch options cljs.pprint/*print-pprint-dispatch*)
cljs.pprint/*print-pretty*
(:pretty options cljs.pprint/*print-pretty*)
cljs.pprint/*print-radix*
(:radix options cljs.pprint/*print-radix*)
cljs.core/*print-readably*
(:readably options cljs.core/*print-readably*)
cljs.pprint/*print-right-margin*
(:right-margin options cljs.pprint/*print-right-margin*)
cljs.pprint/*print-suppress-namespaces*
(:suppress-namespaces
options
cljs.pprint/*print-suppress-namespaces*)]
(binding
[]
(let
[sb
(StringBuffer.)
optval
(if (contains? options :stream) (:stream options) true)
base-writer
(if
(or (true? optval) (nil? optval))
(StringBufferWriter. sb)
optval)]
(if
*print-pretty*
(with-pretty-writer base-writer (write-out object))
(binding [*out* base-writer] (pr object)))
(if (true? optval) (string-print (str sb)))
(if (nil? optval) (str sb)))))))