liveBook · Manning

*print-base*

As explained in Clojure: The Essential Reference

*print-base* is a Clojure dynamic variable specifying the numeric base used when numbers are printed.

*print-base* is a dynamic variable that selects the numeric base used when numbers are printed. Numbers use base 10 by default; temporarily bind another base when a binary or hexadecimal representation is more useful. section 23.20

Printing in binary and hexadecimal

(require '[clojure.pprint :as pprint]) (binding [pprint/*print-base* 2] (pprint/pprint 500)) ;; 111110100 (binding [pprint/*print-base* 16] (pprint/pprint 3405691582)) ;; cafebabe (binding [pprint/*print-base* 16 pprint/*print-radix* true] (pprint/pprint 3405691582)) ;; #xcafebabe section 23.20

Table 23.1. The dynamic variables related to pretty printing

Name

Namespace

Default

Description

*print-readably*

clojure.core

true

Print escape sequences literally.

*print-dup*

clojure.core

false

Print objects so they can be read back into memory.

*print-length*

clojure.core

nil

Number of items to print in a collection.

*print-level*

clojure.core

nil

Number of nesting collections level to print.

*print-meta*

clojure.core

false

Should metadata be printed as part of the object.

*print-pretty*

clojure.pprint

true

Enable/disable pretty printing.

*print-pprint-dispatch*

clojure.pprint

fn

Set pretty printer dispatch function.

*print-right-margin*

clojure.pprint

72

Number of columns to use before breaking into a newline.

*print-miser-width*

clojure.pprint

40

The column at which to enter miser style.

*print-suppress-namespaces*

clojure.pprint

nil

Remove namespace qualifier from symbols.

*print-radix*

clojure.pprint

nil

Print radix used for integers or ratio.

*print-base*

clojure.pprint

10

Change base for printing integers or ratio.

Compare *print-base* with related printing controls, including *print-radix*, which adds base specifiers for binary, octal, and hexadecimal output. section 23.20

How Clojure: The Essential Reference covers it

How deep it goes
Defines the default and demonstrates bound binary and hexadecimal output, but does not explain printing internals.
Examples
Uses 500 in binary and 3405691582 in hexadecimal, with an optional hexadecimal radix marker.
What you can do after
Apply it via binding to print numbers in binary or hexadecimal representations.
How it connects
Connects numeric base selection with pretty printing and *print-radix*.

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.