clojure.pprint/simple-dispatch is the default multimethod used by clojure.pprint to choose formatting behavior from an object's type. It targets human-readable Clojure data structures, including common maps, vectors, sets, sequences, queues, vars, and dereferenced values. section 23.20 section 18.3
The dispatch table includes methods for:
- Persistent maps, vectors, sets, queues, sequences, vars, dereferenceable objects, nil, and a default method. section 23.20
- Generic data rather than Clojure source code; code-shaped lists require the separate code-dispatch strategy for idiomatic indentation. section 18.3
Inspecting and replacing the default dispatch
(require '[clojure.pprint :as pprint]) (pprint/pprint (keys (methods pprint/simple-dispatch))) ;; (nil clojure.lang.PersistentQueue clojure.lang.ISeq :default ;; clojure.lang.IPersistentVector clojure.lang.IPersistentMap ;; clojure.lang.IDeref clojure.lang.IPersistentSet clojure.lang.Var) (def form '(condp = x 1 "one" 2 "two" :else :none)) (pprint/pprint form) ;; (condp ;; = ;; x ;; 1 ;; "one" ;; 2 ;; "two" ;; :else ;; :none) (binding [pprint/*print-pprint-dispatch* pprint/code-dispatch] (pprint/pprint form)) ;; (condp = x ;; 1 "one" ;; 2 "two" ;; :else :none) section 23.20 section 18.3
Table 23.1. The dynamic variables related to pretty printing
| Name |
Namespace |
Default |
Description |
|
|
|
true |
Print escape sequences literally. |
|
|
|
false |
Print objects so they can be read back into memory. |
|
|
|
nil |
Number of items to print in a collection. |
|
|
|
nil |
Number of nesting collections level to print. |
|
|
|
false |
Should metadata be printed as part of the object. |
|
|
|
true |
Enable/disable pretty printing. |
|
|
|
fn |
Set pretty printer dispatch function. |
|
|
|
72 |
Number of columns to use before breaking into a newline. |
|
|
|
40 |
The column at which to enter miser style. |
|
|
|
nil |
Remove namespace qualifier from symbols. |
|
|
|
nil |
Print radix used for integers or ratio. |
|
|
|
10 |
Change base for printing integers or ratio. |
Use the pretty-printing dynamic-variable table to connect dispatch selection with output controls such as pretty printing, line width, nesting level, and collection length. section 23.20
