diff options
author | Tom Faulhaber <git_net@infolace.com> | 2009-06-13 06:07:09 +0000 |
---|---|---|
committer | Tom Faulhaber <git_net@infolace.com> | 2009-06-13 06:07:09 +0000 |
commit | d5fc2809405d09e46e6b92933c28747b3e579860 (patch) | |
tree | 2e940db25195fbacda80a025d1120131d1c7370b /src/clojure/contrib/pprint | |
parent | 356604ca0ec38bf3fbe5a15de715e30142cc3937 (diff) |
pprint: directly call some dispatch functions that we use often to be
easier on the stack
Diffstat (limited to 'src/clojure/contrib/pprint')
-rw-r--r-- | src/clojure/contrib/pprint/dispatch.clj | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/clojure/contrib/pprint/dispatch.clj b/src/clojure/contrib/pprint/dispatch.clj index c27db51d..89ea6b5c 100644 --- a/src/clojure/contrib/pprint/dispatch.clj +++ b/src/clojure/contrib/pprint/dispatch.clj @@ -60,13 +60,49 @@ ;;; are a little easier on the stack. (Or, do "real" compilation, a ;;; la Common Lisp) -(def pprint-simple-list (formatter-out "~:<~@{~w~^ ~_~}~:>")) +;;; (def pprint-simple-list (formatter-out "~:<~@{~w~^ ~_~}~:>")) +(defn pprint-simple-list [alis] + (pprint-logical-block :prefix "(" :suffix ")" + (loop [alis (seq alis)] + (when alis + (write-out (first alis)) + (when (next alis) + (.write #^java.io.Writer *out* " ") + (pprint-newline :linear) + (recur (next alis))))))) + (defn pprint-list [alis] (if-not (pprint-reader-macro alis) (pprint-simple-list alis))) -(def pprint-vector (formatter-out "~<[~;~@{~w~^ ~_~}~;]~:>")) + +;;; (def pprint-vector (formatter-out "~<[~;~@{~w~^ ~_~}~;]~:>")) +(defn pprint-vector [avec] + (pprint-logical-block :prefix "[" :suffix "]" + (loop [aseq (seq avec)] + (when aseq + (write-out (first aseq)) + (when (next aseq) + (.write #^java.io.Writer *out* " ") + (pprint-newline :linear) + (recur (next aseq))))))) + (def pprint-array (formatter-out "~<[~;~@{~w~^, ~:_~}~;]~:>")) -(def pprint-map (formatter-out "~<{~;~@{~<~w~^ ~_~w~:>~^, ~_~}~;}~:>")) + +;;; (def pprint-map (formatter-out "~<{~;~@{~<~w~^ ~_~w~:>~^, ~_~}~;}~:>")) +(defn pprint-map [amap] + (pprint-logical-block :prefix "{" :suffix "}" + (loop [aseq (seq amap)] + (when aseq + (pprint-logical-block + (write-out (ffirst aseq)) + (.write #^java.io.Writer *out* " ") + (pprint-newline :linear) + (write-out (fnext (first aseq)))) + (when (next aseq) + (.write #^java.io.Writer *out* ", ") + (pprint-newline :linear) + (recur (next aseq))))))) + (def pprint-set (formatter-out "~<#{~;~@{~w~^ ~:_~}~;}~:>")) (defn pprint-ref [ref] (pprint-logical-block :prefix "#<Ref " :suffix ">" |