<< Back to previous view

[CLJ-908] Functions with metadata print poorly Created: 10/Jan/12  Updated: 24/May/13  Resolved: 24/May/13

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.3, Release 1.4
Fix Version/s: Release 1.6

Type: Enhancement Priority: Minor
Reporter: Alan Malloy Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: None

Attachments: Text File 0001-Print-metadata-and-anonymous-classes-better.patch     Text File clj-908-Print-metadata-and-anonymous-classes-better-patch2.txt    
Patch: Code
Approval: Ok
Waiting On: Rich Hickey

 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.



 Comments   
Comment by Andy Fingerhut [ 19/May/12 3: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.

Comment by Stuart Sierra [ 09/Nov/12 9:21 AM ]

Screened.

Generated at Thu Oct 23 00:38:31 CDT 2014 using JIRA 4.4#649-r158309.