Print control for Java collection types

87 views
Skip to first unread message

Andy Fingerhut

unread,
Oct 13, 2013, 7:19:21 PM10/13/13
to cloju...@googlegroups.com
CLJ-1270 and the corresponding design page [1] describe this desired enhancement.  The Release.Next planning page [2] says it is in limbo (desired but not done).

I was looking into implementing this enhancement, and had some questions about what changes are desired, exactly.

Is it desired that _every_ object with a class that implements interface java.util.Collection should use print-sequential?

A lot of them already do in Clojure 1.5.1, e.g. those that also implement interface java.util.Set or java.util.List (see below).

However, those with classes implementing interface java.util.Queue or java.beans.beancontext.BeanContext are not printed with print-sequential.  It seems desirable to change java.util.Queue to do so, but I am not so sure about java.beans.beancontext.BeanContext or java.util.Collection in general.
Thanks,
Andy


Some details on java.util.Set and java.util.List:

All objects whose classes implement the java.util.Set interface, such as objects with class java.util.HashSet, already have a printed representation that looks just like Clojure persistent sets, as long as *print-dup* is false (the default).  The method in core_print.clj specialized on interface java.util.Set calls print-sequential, which obeys *print-level* and *print-length* restrictions.  For example:

Clojure 1.5.1
user=> (import '[java.util HashSet])
java.util.HashSet
user=> (def s (HashSet. (range 100)))
#'user/s
user=> (binding [*print-length* 15] (pr-str s))
"#{0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...}"

Similarly, all objects with classes implementing interface java.util.List also have their contents printed using print-sequential, and either parentheses or square brackets around the elements, depending on whether the collection implements interface java.util.RandomAccess or not.

Alex Miller

unread,
Oct 13, 2013, 10:20:47 PM10/13/13
to cloju...@googlegroups.com, cloju...@googlegroups.com
Rich indicated to me that he and Stu had talked at length about this and that Stu will likely be working on the implementation.
--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-dev...@googlegroups.com.
To post to this group, send email to cloju...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojure-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Stuart Halloway

unread,
Oct 18, 2013, 9:43:55 AM10/18/13
to cloju...@googlegroups.com
I have closed this ticket as a duplicate -- the planned work was completed in 1.5, and a print format for Queue would need to be a separate enhancement.


Reply all
Reply to author
Forward
0 new messages