-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ranges: improve printing and conversion to strings #4625
Ranges: improve printing and conversion to strings #4625
Conversation
52ba080
to
dfb7a43
Compare
tst/testinstall/range.tst
Outdated
PrintString: [ 0 .. 2 ] | ||
String: [ 0 .. 2 ] | ||
gap> TestPrintRangeRep([0,2..4]); | ||
ViewObj: [ 0, 2 .. 4 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could go one step further and also print [ 0, 2 .. 4 ]
as [ 0, 2, 4 ]
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The input [ 0, 2, 4 ]
does not produce an object in IsRangeRep
, whereas [ 0, 2 .. 4 ]
creates such an object.
In this sense, I would not be in favour of this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the documentation does not make any claim that the representation is preserved by reentering the output of Print; just that an equal object is returned. So both print outputs conform to the documentation.
In any case, always printing ranges as ranges certainly is also an option; the main motivation for this PR really is to make it behave consistently in one way or the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would support this kind of change, if you want to make it.
Some tests here failing, which will be easy enough to fix, but it'd be nice to first get feedback on the general idea. |
tst/testinstall/range.tst
Outdated
DisplayString: <object> | ||
ViewString: [ 0, -1 ] | ||
PrintString: [ 0, -1 ] | ||
String: [ 0, -1 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: perhaps we do want this to produce [ 0, -1 .. -1 ]
in a few cases; and likewise, [ 0 .. 1 ]
instead of [ 0, 1 ]
. But then IMHO these two should behave consistenly: either both kinds of ranges of length 2 are shown "as range", or both are shown "as lists". Also, of course ViewString
and ViewObj
should be consistent, and likewise PrintString
and PrintObj
. (Well... and DisplayString
, but I did not even try to fix that in this PR)
dfb7a43
to
a3c09ff
Compare
I don't have time to properly review at the moment, but I do like the general idea from what I can get at a glance. However, I worry that it suffers from the same problem as #4050, i.e. breaks the tests of various packages, which will make it annoying to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me try to summarize what this pull request changes.
- For ranges of length two,
Display
,PrintObj
,PrintString
, andString
now show the two entries separated by a comma; up to now, the..
notation was used. The output ofViewObj
(using a comma) was not changed.ViewString
uses a comma before and after the change, but the hints\>
and\<
that were present before the change have now disappeared. - For ranges with at least three elements, now there is a special
ViewString
method that uses the..
notation; up to now, all entries of the range were listed. I regard the pull request as a bugfix in this respect. (One could discuss whether the hints\>
and\<
should be inserted.)
From the viewpoint of consistency w.r.t. the operations in question, now ranges with at least three elements are shown as ranges if they store that they are ranges, and ranges of length two are not shown as ranges. (Ranges of length at most one do not store that they are ranges.)
Concerning the impact of the change on package tests, I have not found differences in the basic tests for my packages CTblLib, AtlasRep, and CTBlocks. Perhaps there are some differences in the tests of other packages, but I think that the changes proposed in #4050 (mentioned by @wilfwilson ) cause significantly more trouble.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked at this in more detail now and I do support it the changes, in particular the consistency and the showing length-two ranges like [1..2]
as [1,2]
. I would support further such changes in this direction (e.g. [1,3..5] being [1,3,5]).
@ThomasBreuer raises a good point about the \>
and \<
hints.
I agree with @ThomasBreuer that this PR should not be anyway near as disruptive as #4050, but it causes at least some problems. Running the standard tests of Digraphs and Semigroups with this PR I get:
- Digraphs:
6 failures in 2 of 16 files
- Semigroups:
11 failures in 3 of 67 files
It should be easy to fix such problems by suppressing output. Hopefully it will be easy enough to detect affected packages.
Note that the CI is currently not passing.
tst/testinstall/range.tst
Outdated
PrintString: [ 0 .. 2 ] | ||
String: [ 0 .. 2 ] | ||
gap> TestPrintRangeRep([0,2..4]); | ||
ViewObj: [ 0, 2 .. 4 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would support this kind of change, if you want to make it.
tst/testinstall/reesmat.tst
Outdated
@@ -270,7 +270,7 @@ false | |||
|
|||
# IsReesMatrixSemigroup: for a Rees matrix subsemigroup with generators, 1 | |||
gap> R := ReesMatrixSemigroup(SymmetricGroup(2), [[(1,2)]]); | |||
<Rees matrix semigroup 1x1 over Sym( [ 1 .. 2 ] )> | |||
<Rees matrix semigroup 1x1 over Sym( [ 1, 2 ] )> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are quite a few of these kinds of changes in Semigroups and Digraphs, (almost?) all of which involve Sym( [ 1 .. 2 ] )
becoming Sym( [ 1, 2 ] )
a3c09ff
to
d554eca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have - will impact package tests, but with the advent of https://github.com/gap-system/PackageDistro/ that can be then systematically addressed. Some packages may need more work to adapt examples to pass in both new and old GAP versions.
d554eca
to
9a2e32e
Compare
... to match ViewObj and Display. As a result, Display, PrintObj, DisplayString, PrintString and String now all behave the same for ranges, while ViewObj and ViewString differ. This is probably quite surprising to people, but changing it one way or the other will affect packages, so for now let's play it safe and only address the "obvious" bugs.
9a2e32e
to
de03049
Compare
I have now revised the changes in this PR, going in a somewhat different direction: instead of trying to align ViewObj with PrintObj and Display, I've opted to only "fix" The result is still a bit odd because now the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if lists with three elements like [0,2..4] should be “printed” as [0, 2, 4] instead of [0, 2 .. 4]
"Should"? Dunno.... "Could"? Sure. But any such change has a cost, you need to at least update all packages whose test suites depend on the printing. IMHO it is not worth the trouble |
Sure, I should have used could. |
The diff between the first and second commit shows what changed.
Perhaps we should have similar tests for other library objects?
This patch has been motivated by the CI failure I observed here: https://github.com/gap-packages/fr/pull/38/checks?check_run_id=3160342361