Printing of array-valued elements

Robert Field robert.field at oracle.com
Sat Aug 8 00:43:00 UTC 2015


Thanks.  I could see having a setting for value length, as that applies to any value output.  And it could be used for array formatting.

-Robert

> On Aug 7, 2015, at 6:39 AM, Som Snytt <som.snytt at gmail.com> wrote:
> 
> Scala REPL goes to some length to pretty print appropriately. (Sorry, pun alert.)
> 
> https://github.com/scala/scala/blob/2.11.x/src/library/scala/runtime/ScalaRunTime.scala#L321 <https://github.com/scala/scala/blob/2.11.x/src/library/scala/runtime/ScalaRunTime.scala#L321>
> 
> Once the facility is available, many people ask how to get their arrays to print like that.
> 
> There's a max line length which is usually hit before the max array length to format. It's possible to bump the length from the REPL, because it's annoying when the end of a lengthy result is clipped.
> 
> I like the idea of replacing a trailing ellipsis with the last few array elements, at least for arrays of primitives. That's trickier for deepToString.
> 
> 
> 
> On Thu, Aug 6, 2015 at 4:16 PM, Robert Field <robert.field at oracle.com <mailto:robert.field at oracle.com>> wrote:
> As always in Java, there will be objects which only print out well when using a custom print method (which is easy to do in JShell), special-casing seems like complexity with payback that would rarely be used (or known to exist).
> 
> -Robert
> 
> > On Aug 6, 2015, at 12:53 AM, Ben Evans <benjamin.john.evans at gmail.com <mailto:benjamin.john.evans at gmail.com>> wrote:
> >
> > Should "bigness" be a configurable parameter? I can see it being
> > irritating to have an array that is just too big to be printed out in
> > full.
> >
> > On Mon, Aug 3, 2015 at 10:13 PM, Jonathan Gibbons
> > <jonathan.gibbons at oracle.com <mailto:jonathan.gibbons at oracle.com>> wrote:
> >>
> >>
> >> On 08/03/2015 12:31 PM, Brian Goetz wrote:
> >>>
> >>> The toString() method on arrays is generally unhelpful (inherited from
> >>> Object.)  Since jshell is a read-eval-PRINT loop, it might be nice to print
> >>> the result of array-valued expressions in a friendlier manner, such as by
> >>> using Arrays.toString(array) instead of array.toString(). (Might want to
> >>> limit this to arrays of below a certain length.  (Might want to allow that
> >>> limit to be set by preferences.))
> >>>
> >>> So we'd get
> >>>
> >>> [ 1, 2, 3 ]
> >>>
> >>> instead of
> >>>
> >>> [I at 2048230
> >>>
> >>
> >> If arrays are big, how about printing "the first few" and "the last few",
> >> separate by "...", as in
> >>
> >> [ 1, 2, 3, ..., 98, 99, 100 ]
> >>
> >> -- Jon
> 
> 



More information about the kulla-dev mailing list