1. display() and its pretty format

The documentation for console:display says:

console:display said...

If data_in is a simple text string, then args can be used to produce a formatted output with data_in providing the text:format string and args being a sequence containing the data to be formatted.

The documentation for text:format says:

text:format said...

Any sequence argument that is not a string will be converted to its pretty format before being used in token replacement.

The following code seems to demonstrate otherwise:

sequence s1 = { 
    {1,2,3}, 
    {5,5,6}, 
    {7,8,9} 
} 
 
display( "s1 = []", {s1} ) 

s1 = {{1,2,3},{5,5,6},{7,8,9}} 

I would expect this output instead:

s1 = { 
  {1,2,3}, 
  {5,5,6}, 
  {7,8,9} 
} 

Which I get with this code:

display( "s1 = _" ) 
display( s1 ) 

Am I doing something wrong here or is this not the intended output?

-Greg

new topic     » topic index » view message » categorize

2. Re: display() and its pretty format

ghaberek said...

Am I doing something wrong here or is this not the intended output?

Good question. I'll look into that, but I'm guessing that it depends on one's idea of what "pretty" means.

new topic     » goto parent     » topic index » view message » categorize

3. Re: display() and its pretty format

DerekParnell said...

Good question. I'll look into that, but I'm guessing that it depends on one's idea of what "pretty" means.

I think we've effectively defined "pretty" here: Pretty Printing.

docs said...

Print an object to a file or device, using braces {,,,}, indentation, and multiple lines to show the structure.

-Greg

new topic     » goto parent     » topic index » view message » categorize

4. Re: display() and its pretty format

ghaberek said...
DerekParnell said...

Good question. I'll look into that, but I'm guessing that it depends on one's idea of what "pretty" means.

I think we've effectively defined "pretty" here: Pretty Printing.

docs said...

Print an object to a file or device, using braces {,,,}, indentation, and multiple lines to show the structure.

-Greg

Ok, both display() and format() use the pretty_print() routine. The difference is that when display() is called without any formatting tokens, it uses pretty_print() with the prettifying argument as {2}, but when display() is called using formatting tokens, it calls pretty_print() using the prettifying argument of {2,0,1,1000,"%d",fmt,32,127,1,0}. To save you looking up the meaning of all those options, the first one uses all the defaults for pretty printing (2-col indent, line breaks at end of subsequences, etc) but the second one explicitly says something along the lines of... make the pretty string one single line and make it as short as possible.

If you require an enhancement to format() to enable it to be supplied with prettifying options of your own choice, we can add that to the list of things to do.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu