(get-pretty-writer writer)
Returns the IWriter passed in wrapped in a pretty writer proxy, unless it's
already a pretty writer. Generally, it is unnecessary to call this function, since pprint,
write, and cl-format all call it if they need to. However if you want the state to be
preserved across calls, you will want to wrap them with this.
For example, when you want to generate column-aware output with multiple calls to cl-format,
do it like in this example:
(defn print-table [aseq column-width]
(binding [*out* (get-pretty-writer *out*)]
(doseq [row aseq]
(doseq [col row]
(cl-format true "~4D~7,vT" col column-width))
(prn))))
Now when you run:
user> (print-table (map #(vector % (* % %) (* % % %)) (range 1 11)) 8)
It prints a table of squares and cubes for the numbers from 1 to 10:
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
Source
(defn
get-pretty-writer
"Returns the IWriter passed in wrapped in a pretty writer proxy, unless it's\nalready a pretty writer. Generally, it is unnecessary to call this function, since pprint,\nwrite, and cl-format all call it if they need to. However if you want the state to be\npreserved across calls, you will want to wrap them with this.\n\nFor example, when you want to generate column-aware output with multiple calls to cl-format,\ndo it like in this example:\n\n (defn print-table [aseq column-width]\n (binding [*out* (get-pretty-writer *out*)]\n (doseq [row aseq]\n (doseq [col row]\n (cl-format true \"~4D~7,vT\" col column-width))\n (prn))))\n\nNow when you run:\n\n user> (print-table (map #(vector % (* % %) (* % % %)) (range 1 11)) 8)\n\nIt prints a table of squares and cubes for the numbers from 1 to 10:\n\n 1 1 1\n 2 4 8\n 3 9 27\n 4 16 64\n 5 25 125\n 6 36 216\n 7 49 343\n 8 64 512\n 9 81 729\n 10 100 1000"
[writer]
(if
(pretty-writer? writer)
writer
(pretty-writer writer *print-right-margin* *print-miser-width*)))