Pretty printing generates readable textual representations by adding layout, spacing, and line breaks beyond basic printing. In Clojure, clojure.pprint provides REPL-ready pprint and pp functions, plus write for configurable output. section 18.3
The main controls and applications include:
- Use pprint or pp for readable Clojure data, and write when overriding options such as :stream, :base, :length, and :level. section 18.3
- Limit collection size with *print-length* and nesting depth with *print-level*; truncated items appear as … and truncated branches as #. section 23.20
- Select a dispatch strategy for the data being printed: simple-dispatch suits general structures, while code-dispatch formats Clojure source. section 18.3 section 23.20
- Tune presentation with *print-pretty*, *print-right-margin*, *print-miser-width*, namespace suppression, metadata, numeric bases, and output streams. section 23.20
- Use print-table to render maps or map sequences as aligned two-dimensional tables. section 18.3
Readable data, formatted code
A nested value such as {:a ["red" "blue" "green"], :b '(:north :south :east :west')} prints across several lines with pprint. For source code, binding clojure.pprint/code-dispatch around pprint preserves forms such as (condp = x 1 "one" ...) in a code-oriented layout instead of treating them as generic data. section 18.3 section 23.20
(def data {:a ["red" "blue" "green"]
:b '(:north :south :east :west)
:c {"x-axis" 1 "y-axis" 2}})
data ; #1
;; {:a ["red" "blue" "green"], :b (:north :south :east :west), :c {"x-axis" 1, "y-axis" 2}}
(pp) ; #2
;; {:a ["red" "blue" "green"],
;; :b (:north :south :east :west),
;; :c {"x-axis" 1, "y-axis" 2}}
(pprint data) ; #3
;; {:a ["red" "blue" "green"],
;; :b (:north :south :east :west),
;; :c {"x-axis" 1, "y-axis" 2}}
Compare ordinary data printing with pprint's added line breaks and indentation on the same nested value. section 18.3


