Functions with metadata print poorly

Description

1.3 removed the metadata slot on most functions, and made .withMeta return a new wrapping function that provides metadata. This changes the way functions with metadata print: instead of #<user$eval595$fn_596 user$eval595$fn_596@3d48ff04> we now see #< clojure.lang.AFunction$1@581de498>. I might argue that we should "lie" and print the class of the original wrapped function since it's more useful than AFunction$1, but that's debatable. The two things I propose changing are:

  1. When print-meta is true, we should print the metadata map for functions. That nothing prints implies there is no metadata, which can make it difficult to track down bugs related to metadata on functions.

  2. Remove the errant space at the front of the printed representation of functions with meta, changing #< clojure.lang.AFunction$1@581de498> to #<clojure.lang.AFunction$1@581de498>. The cause of this issue is that .getSimpleName on an object with an anonymous class returns "", and we print that followed by a space and its .toString. My fix is to omit the extra space if the class has no simple name; this would cause instances of other anonymous (non-function) classes to print more nicely as well.

If it would be desirable to print the class of the original "wrapped" function, then I can easily add another patch for that.

Environment

None

Attachments

2

Activity

Show:

Stuart Sierra November 9, 2012 at 3:21 PM

Screened.

Andy Fingerhut May 19, 2012 at 9:30 AM

clj-908-Print-metadata-and-anonymous-classes-better-patch2.txt dated May 19, 2012 only has context line changes from the previous one, 0001-Print-metadata-and-anonymous-classes-better.patch dated Jan 10, 2012. The previous one no longer applies cleanly to the latest master, while the new one does.

Completed

Details

Assignee

Reporter

Approval

Ok

Patch

Code

Priority

Affects versions

Fix versions

Created January 10, 2012 at 11:15 PM
Updated May 24, 2013 at 1:55 PM
Resolved May 24, 2013 at 1:55 PM