arr-ai / arrai

The ultimate data engine.
http://arr.ai
Apache License 2.0
20 stars 15 forks source link

Fix issues with pretty printing #535

Closed orlade-anz closed 4 years ago

orlade-anz commented 4 years ago

Fixes #516, part of https://github.com/arr-ai/arrai/issues/171.

Changes proposed in this pull request:

Checklist:

orlade-anz commented 4 years ago
@> //fmt.pretty([1,2,3])
'[\n  1,\n  2,\n  3\n]'
@>

Current output is not right.

It's not perfect, but I'd argue it's more correct that it was. Simple lists should be flat, but in practice, most lists are not simple. Expanding simple lists is a better interim than flattening non-simple lists as we do today.

ericzhang6222 commented 4 years ago
@> //fmt.pretty([1,2,3])
'[\n  1,\n  2,\n  3\n]'
@>

Current output is not right.

It's not perfect, but I'd argue it's more correct that it was. Simple lists should be flat, but in practice, most lists are not simple. Expanding simple lists is a better interim than flattening non-simple lists as we do today.

I think the issue is code return rel.NewString([]rune(prettifiedString)), nil in std_fmt.go. All \n is transformed to char \n and will not start a new line really.

marcelocantos commented 4 years ago

This is correct behaviour. The purpose of //fmt.pretty is to return a string with the correctly formatted content, not to print that string. When evaluated in ai, this shows that string in arr.ai syntax. Compare with Python:

In [1]: import pprint                                                                                                                                                                                          

In [2]: pprint.pp([1, 2, 3])                                                                                                                                                                                   
[1, 2, 3]

In [3]: pprint.pformat([1, 2, 3])                                                                                                                                                                              
Out[3]: '[1, 2, 3]'

pprint.pp prints the string, while pprint.pformat returns the string and ipython3 shows what that string is in Python syntax. The intent behind //fmt.pretty is the same as pprint.pformat.

The intended behaviour will manifest with:

arrai eval '//fmt.pretty([1,2,3])'
coveralls commented 4 years ago

Pull Request Test Coverage Report for Build 01bd08ce080c0488b1feb2170f1fbfb2105dd2da-PR-535


Changes Missing Coverage Covered Lines Changed/Added Lines %
syntax/prettify.go 63 75 84.0%
<!-- Total: 64 76 84.21% -->
Files with Coverage Reduction New Missed Lines %
rel/value_set_str.go 2 60.82%
<!-- Total: 2 -->
Totals Coverage Status
Change from base Build b7a28242d7549a562daf65d9d9dd7d16ef814484: 0.2%
Covered Lines: 4503
Relevant Lines: 9399

💛 - Coveralls
orlade-anz commented 4 years ago

Some test cases are failed.

Fixed I believe.