1. display() and its pretty format
- Posted by ghaberek (admin) Aug 13, 2015
- 1488 views
The documentation for console:display says:
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:
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
2. Re: display() and its pretty format
- Posted by DerekParnell (admin) Aug 14, 2015
- 1430 views
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.
3. Re: display() and its pretty format
- Posted by ghaberek (admin) Aug 15, 2015
- 1384 views
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.
-Greg
4. Re: display() and its pretty format
- Posted by DerekParnell (admin) Aug 16, 2015
- 1396 views
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.
-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.