liveBook · Manning

*print-meta*

As explained in Clojure: The Essential Reference

*print-meta* is a Clojure dynamic variable controlling whether metadata is included in readable printed representations.

*print-meta* is a Clojure dynamic variable that controls whether metadata appears in readable printed representations. When enabled, metadata is emitted by serialization-oriented functions such as pr, prn, pr-str, and prn-str. section 23.20

Round-tripping metadata

Bind *print-meta* to true while printing a metadata-bearing value: (def s (binding [*print-meta* true] (pr-str (with-meta [1 2 3] {:my :meta})))). The resulting string is ^{:my :meta} [1 2 3]. Reading it back with read-string produces [1 2 3] whose metadata is {:my :meta}.

How Clojure: The Essential Reference covers it

How deep it goes
Defines the toggle and demonstrates metadata round-tripping, without detailing printer internals.
Examples
Uses a metadata-bearing vector, pr-str output, read-string, and meta to demonstrate preservation.
What it assumes
Assumes familiarity with Clojure metadata, readable printing, and reading values from strings.
What you can do after
Apply it via binding to include metadata in readable serialized output and recover that metadata with read-string.
How it connects
Connects metadata with pr-str, read-string, with-meta, and dynamic binding.

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.