diff options
author | Tom Faulhaber <git_net@infolace.com> | 2009-07-06 09:28:49 -0700 |
---|---|---|
committer | Tom Faulhaber <git_net@infolace.com> | 2009-07-06 09:28:49 -0700 |
commit | 0d2919855b1cc18f21e08fb4ee4a8c32445582e0 (patch) | |
tree | 33fc7aa29e44cd687d1349f31bea6c65bb722ca9 /src/clojure/contrib/pprint/cl-format.clj | |
parent | d6e7b65cdc0b9432b0b13215ac5ccf2e2ef81631 (diff) |
Support for *print-base* and *print-radix* in cl-format, pprint and write.
Diffstat (limited to 'src/clojure/contrib/pprint/cl-format.clj')
-rw-r--r-- | src/clojure/contrib/pprint/cl-format.clj | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/clojure/contrib/pprint/cl-format.clj b/src/clojure/contrib/pprint/cl-format.clj index de547e43..64fc4f30 100644 --- a/src/clojure/contrib/pprint/cl-format.clj +++ b/src/clojure/contrib/pprint/cl-format.clj @@ -158,9 +158,29 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm ;;; Common handling code for ~A and ~S ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(declare *print-base* *print-radix*) +(declare opt-base-str) + +(def #^{:private true} + special-radix-markers {2 "#b" 8 "#o", 16 "#x"}) + +(defn- format-simple-number [n] + (cond + (integer? n) (if (= *print-base* 10) + (str n (if *print-radix* ".")) + (str + (if *print-radix* (or (get special-radix-markers *print-base*) (str "#" *print-base* "r"))) + (opt-base-str *print-base* n))) + (ratio? n) (str + (if *print-radix* (or (get special-radix-markers *print-base*) (str "#" *print-base* "r"))) + (opt-base-str *print-base* (.numerator n)) + "/" + (opt-base-str *print-base* (.denominator n))) + :else nil)) + (defn- format-ascii [print-func params arg-navigator offsets] (let [ [arg arg-navigator] (next-arg arg-navigator) - #^String base-output (print-func arg) + #^String base-output (or (format-simple-number arg) (print-func arg)) base-width (.length base-output) min-width (+ base-width (:minpad params)) width (if (>= min-width (:mincol params)) |