Back

*print-radix* (clj)

(source)

variable

Print a radix specifier in front of integers and rationals. If *print-base* is 2, 8, or 16, then the radix specifier used is #b, #o, or #x, respectively. Otherwise the radix specifier is in the form #XXr where XX is the decimal value of *print-base*

Examples

yaml/yamlscript
(ns a0.patch-pprint
  (:require [clojure.pprint :as pprint]))

(def new-write
  (fn [object & kw-args]
    (let [options (merge {:stream true} (apply hash-map kw-args))]
      #_:clj-kondo/ignore
      (with-bindings (new-table-ize pprint/write-option-table options)
        (with-bindings
          (if (or (not (= pprint/*print-base* 10)) pprint/*print-radix*)
            {#'pr @#'pprint/pr-with-base} {})
          (let [optval (if (contains? options :stream)
                         (:stream options)
                         true)
                base-writer (condp = optval
                              nil (java.io.StringWriter.)
                              true *out*
                              optval)]
            (if pprint/*print-pretty*
              (pprint/with-pretty-writer base-writer
                (pprint/write-out object))
              (binding [*out* base-writer]
                (pr object)))
            (when (nil? optval)
              (.toString ^java.io.StringWriter base-writer))))))))
reborg/clojure-essential-reference
(require '[clojure.pprint :as pretty])

(doc pretty/write) ; <1>
;; -------------------------
;; clojure.pprint/write
;; ([object & kw-args])
;; Write an object subject to the current bindings of the printer control variables.
;; Use the kw-args argument to override individual variables for this call (and any
;; recursive calls). Returns the string result if :stream is nil or nil otherwise.
;;
;; The following keyword arguments can be passed with values:
;;   Keyword              Meaning                              Default value
;;   :stream              Writer for output or nil             *out*
;;   :base                Base to use for writing rationals    *print-base*
;;   :length              Maximum elements to show in sublists *print-length*
;;   :level               Maximum depth                        *print-level*
;;   :miser-width         Width to enter miser mode            *print-miser-width* ; <2>
;;   :dispatch            The pretty print dispatch function   *print-pprint-dispatch*
;;   :pretty              If true, do pretty printing          *print-pretty*
;;   :radix               If true, prepend a radix specifier   *print-radix*
;;   :right-margin        The column for the right margin      *print-right-margin*
;;   :suppress-namespaces If true, no namespaces in symbols    *print-suppress-namespaces*