liveBook · Manning

*print-pprint-dispatch*

As explained in Clojure: The Essential Reference

*print-pprint-dispatch* is a Clojure dynamic variable holding the multimethod that selects pretty-printing strategies.

*print-pprint-dispatch* is a Clojure dynamic variable containing the multimethod that selects a pretty-printing strategy from an object’s type. Its default value is clojure.pprint/simple-dispatch, which formats common Clojure data structures for human-readable output. section 23.20

Bind it locally when output needs another formatting strategy. clojure.pprint/code-dispatch formats Clojure source-like data, while with-pprint-dispatch provides a macro for the same local switch. section 23.20

Formatting a conditional expression

A normal pretty print spreads the form across many lines. Binding code-dispatch produces source-oriented indentation: (binding [pprint/*print-pprint-dispatch* pprint/code-dispatch] (pprint/pprint '(condp = x 1 "one" 2 "two" :else :none))) ;; (condp = x ;; 1 "one" ;; 2 "two" ;; :else :none)

How Clojure: The Essential Reference covers it

How deep it goes
Defines the dynamic multimethod contract and demonstrates local strategy switching, but does not detail custom dispatch methods.
Examples
Demonstrates default formatting versus code-dispatch formatting for a condp expression.
What it assumes
Assumes familiarity with Clojure dynamic binding, multimethods, clojure.pprint, and quoted data structures.
What you can do after
Operate/configure pretty printing by locally binding the dispatch variable or using with-pprint-dispatch.
How it connects
Connects pretty printing with dynamic variables, multimethods, and Clojure source-code formatting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.