JShell: result truncation

Robert Field robert.field at oracle.com
Thu Sep 22 23:47:14 UTC 2016


[Was: Re: JShell: representation of array values]

John, Jon,

Thanks for the comments.  Some context is needed.  This is the JShell 
stack (a prettier, more detailed view attached):

    jshell tool
    -- JShell API --
    JShell core implementation
    -- JShell SPI --
    JShell execution engine

Returned execution values, through both interfaces, and thus in the core 
implementation and tool are Strings.
The execution engine is charged with translating returned values into a 
String representation.  This is where the work to provide a better 
representation of arrays was done.
No truncation is done (for any kind of value) at the execution engine level.

Truncation is done only in the tool.   And it is configurable.  See 
/help output below.

I don't want to push configurable truncation through all those layers.  
So, we are stuck with truncation being stupid (not in terms of context) 
in terms of the kind of value it is truncating.
Truncation is operating on Strings for which it knows nothing of their 
structure or content.
They might be a long String, List, or ...

That said, it better for whatever the truncated thing is to have a bit 
of terminal context.

A String:

        "abcdefg ... xyz"

A List:

        [1, 2, 3, 4, ... 999]

An array:

        boolean[233] { false, false, false, false, f ... se }

So, there could be a length of termination context argument.

-Robert


jshell> /help /set truncation
|  Set the max length a displayed value.
|
|       /set truncation <mode> <length> <selector>...
|
|  Where <mode> is the name of a previously defined feedback mode -- see 
'/help /set mode'.
|  Where <length> is an unsigned integer representing a maximum length.
|  Where <selector> is only needed if you wish to fine-tune value 
truncation length
|  by context, <selector> is the context in which the truncation is applied.
|  The structure of selector is a hyphen separated list of selector kind 
lists.
|  A selector kind list is a comma separated list of values of one 
selector kind.
|  A selector matches if each selector kind list matches; A selector 
kind list
|  matches if one of the values matches.
|
|  Below are the relevant selector kinds for truncation.
|
|  The case selector kind describes the kind of snippet.  The values are:
|       vardecl    -- variable declaration without init
|       varinit    -- variable declaration with init
|       expression -- expression -- note: {name}==scratch-variable-name
|       varvalue   -- variable value expression
|       assignment -- assign variable
|       The action selector kind describes what happened to the 
snippet.  The values are:
|       added     -- snippet has been added
|       modified  -- an existing snippet has been modified
|       replaced  -- an existing snippet has been replaced with a new 
snippet
|  Examples:
|       /set trunc mymode 80
|       /set truncation mymode 45 expression
|       /set truncation mymode 0 vardecl-modified,replaced
|
|  Note that subsequent selectors for a field may overwrite some or all 
of previous used selectors -- last one wins



On 09/22/16 10:42, Jonathan Gibbons wrote:
> In the long array case, I'd suggest to hide the middle, not the end of 
> the array.  Show the first "few" entries and the last "few" entries in 
> the array, for some value of "few".
>
> -- Jon
>
>
> On 9/22/16 10:37 AM, John Rose wrote:
>> On Sep 21, 2016, at 6:16 PM, Robert Field <robert.field at oracle.com> 
>> wrote:
>>> Comments???
>> Another +1 from me.  Some comments from my inner Common Lisper:
>>
>> There should be a close brace after the "…" of an overlong array.
>> This will allow syntax sensitive editors (emacs!) to block the thing 
>> correctly.
>>
>> The cutoff length of the overlong array should be a configurable number.
>>
>> You might consider a configurable cutoff for printed nesting level.
>>
>> These ideas from from this section of the CL manual:
>>
>> http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node193.html#LEVELLENGTHTABLE 
>>
>>
>> There is also an option called *print-array* which gates whether 
>> arrays should be expanded at all.
>> This is relevant to Java, which also distinguishes Arrays.toString 
>> from Object.toString.
>>
>> — John
>



More information about the kulla-dev mailing list