Print control for Java collection types

Showing 1-3 of 3 messages
Print control for Java collection types Andy Fingerhut 10/13/13 4:19 PM
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.

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])
user=> (def s (HashSet. (range 100)))
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.
Re: Print control for Java collection types Alex Miller 10/13/13 7:20 PM
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
To post to this group, send email to
Visit this group at
For more options, visit
Re: Print control for Java collection types Stuart Halloway 10/18/13 6:43 AM
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.