<< Back to previous view

[CLJ-1471] Option to print type info Created: 21/Jul/14  Updated: 21/Jul/14

Status: Open
Project: Clojure
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Minor
Reporter: Pascal Germroth Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: pprint


I've had an issue with defrecord-types being converted into ordinary maps somewhere, which was relatively hard to track down inside a deep structure since they are pprinted as the same thing by default.
The following code patches into the pprint dispatch and prints the type around values; it turned out to be quite useful, but feels hackish.
Maybe something like that would be useful to integrate into clojure.pprint directly (there are a number of cosmetic options already), i.e. into clojure.pprint/write-out.

Only printing (type) may not be enough in some cases; so an option to print all metadata would be nice.
Maybe something like :metadata nil as default, :metadata :type to print types (but also for non-IMetas, using (type) and :metadata true to print metadata for IMetas using (meta).

(defn pprint-with-type
  ([object] (pprint object *out*))
  ([object writer]
   ; keep original dispatch.
   ; calling it directly will print only that object,
   ; but return to our dispatch for subobjects.
   (let [dispatch clojure.pprint/*print-pprint-dispatch*]
     (binding [clojure.pprint/*print-pprint-dispatch*
               (fn [obj]
                 (if (instance? clojure.lang.IMeta obj)
                   (do (print "^{:type ")
                       (dispatch (type obj))
                       (print "} ")
                       (clojure.pprint/pprint-newline :fill)
                       (dispatch obj))
                   (do (print "(^:type ")
                       (dispatch (type obj))
                       (print " ")
                       (clojure.pprint/pprint-newline :fill)
                       (dispatch obj)
                       (print ")"))))]
       (clojure.pprint/pprint object writer)))))

[CLJ-1123] UNIX/Windows line endings - clojure.pprint tests cause failure in Windows build Created: 09/Dec/12  Updated: 10/Dec/12  Resolved: 10/Dec/12

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.5
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Mike Anderson Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: platform-specific, pprint

Windows 7, Maven 3.0.4


I ran a test build of the latest Clojure 1.5 master (372f03e) on Windows and found a number of failures in the "clojure.test-clojure.pprint" tests. All of these seem to be caused by incorrect assumptions about line endings. Example:

[java] {:clojure.test/vars (ns-macro-test),
[java] :thread/name "main",
[java] :pid 1528,
[java] :thread 1,
[java] :type :assert/fail,
[java] :level :warn,
[java] :test/actual
[java] (not
[java] (clojure.core/=
[java] "(ns slam.hound.stitch\r\n (:use [slam.hound.prettify :only [prettify]]))\r\n"
[java] "(ns slam.hound.stitch\n (:use [slam.hound.prettify :only [prettify]]))\n")),
[java] :test/expected
[java] (clojure.core/=
[java] (clojure.core/with-out-str
[java] (clojure.pprint/with-pprint-dispatch
[java] clojure.pprint/code-dispatch
[java] (clojure.pprint/pprint
[java] (clojure.core/read-string
[java] "(ns slam.hound.stitch\n (:use [slam.hound.prettify :only [prettify]]))"))))
[java] (clojure.core/str
[java] "(ns slam.hound.stitch\n (:use [slam.hound.prettify :only [prettify]]))"
[java] "\n")),
[java] :line 173,
[java] :tstamp 1355113319212,
[java] :file "test_pretty.clj"}

It isn't totally clear what the right behaviour should be: should pprint be producing platform specific line endings or not? Either way, the test should confirm the expected behaviour.

Comment by Andy Fingerhut [ 10/Dec/12 1:57 AM ]

Most likely this should be closed as a duplicate of CLJ-1076. The symptoms sound the same, and CLJ-1076 has a patch for it that should fix the problem.

Comment by Mike Anderson [ 10/Dec/12 2:03 AM ]

Hi Andy - yes this looks like a duplicate, thanks for spotting. Should be closed.

Comment by Andy Fingerhut [ 10/Dec/12 11:45 AM ]

Duplicate of CLJ-1076

Generated at Thu Jul 24 14:24:52 CDT 2014 using JIRA 4.4#649-r158309.