Skip to content

Commit

Permalink
Fix ViewString and DisplayString for ranges
Browse files Browse the repository at this point in the history
... 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.
  • Loading branch information
fingolfin committed Aug 3, 2022
1 parent d8fc20f commit de03049
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
32 changes: 30 additions & 2 deletions lib/list.gi
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,34 @@ local str,ls, i;
return str;
end );

InstallMethod( DisplayString,
"for a range",
[ IsRange ],
range -> Concatenation( String( range ), "\n" ) );

InstallMethod( ViewString,
"for a range",
[ IsRange ],
function( list )
local str;
str := "[ ";
Append( str, String( list[1] ) );
if Length( list ) > 1 then
if Length(list) = 2 or list[2] - list[1] <> 1 then
Append( str, ", " );
Append( str, String( list[2] ) );
fi;
if Length(list) > 2 then
Append( str, " .. " );
Append( str, String( list[ Length( list ) ] ) );
fi;
fi;
Append( str, " ]" );
Assert(0, IsStringRep(str));
ConvertToStringRep( str );
return str;
end );

InstallMethod( String,
"for a range",
[ IsRange ],
Expand Down Expand Up @@ -3829,7 +3857,7 @@ LIST_WITH_IDENTICAL_ENTRIES );
## and in the 'ViewString' method for finite lists.
##
InstallMethod( ViewObj,
"for finite lists",
"for a finite list",
[ IsList and IsFinite ],
{} -> RankFilter(IsList) + 1 - RankFilter(IsList and IsFinite),
function( list )
Expand Down Expand Up @@ -3857,7 +3885,7 @@ function( list )
end );

InstallMethod( ViewObj,
"for ranges",
"for a range",
[ IsList and IsFinite and IsRange ],
function( list )
Print( "[ " );
Expand Down
16 changes: 8 additions & 8 deletions tst/testinstall/range.tst
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,39 @@ gap> TestPrintRangeRep:=function(r)
#
gap> TestPrintRangeRep([0..1]);
Display: [ 0 .. 1 ]
DisplayString: <object>
DisplayString: [ 0 .. 1 ]
ViewObj: [ 0, 1 ]
ViewString: [ 0, 1 ]
PrintObj: [ 0 .. 1 ]
PrintString: [ 0 .. 1 ]
String: [ 0 .. 1 ]
gap> TestPrintRangeRep([0..2]);
Display: [ 0 .. 2 ]
DisplayString: <object>
DisplayString: [ 0 .. 2 ]
ViewObj: [ 0 .. 2 ]
ViewString: [ 0, 1, 2 ]
ViewString: [ 0 .. 2 ]
PrintObj: [ 0 .. 2 ]
PrintString: [ 0 .. 2 ]
String: [ 0 .. 2 ]
gap> TestPrintRangeRep([0,2..4]);
Display: [ 0, 2 .. 4 ]
DisplayString: <object>
DisplayString: [ 0, 2 .. 4 ]
ViewObj: [ 0, 2 .. 4 ]
ViewString: [ 0, 2, 4 ]
ViewString: [ 0, 2 .. 4 ]
PrintObj: [ 0, 2 .. 4 ]
PrintString: [ 0, 2 .. 4 ]
String: [ 0, 2 .. 4 ]
gap> TestPrintRangeRep([0,-1..-2]);
Display: [ 0, -1 .. -2 ]
DisplayString: <object>
DisplayString: [ 0, -1 .. -2 ]
ViewObj: [ 0, -1 .. -2 ]
ViewString: [ 0, -1, -2 ]
ViewString: [ 0, -1 .. -2 ]
PrintObj: [ 0, -1 .. -2 ]
PrintString: [ 0, -1 .. -2 ]
String: [ 0, -1 .. -2 ]
gap> TestPrintRangeRep([0,-1..-1]);
Display: [ 0, -1 .. -1 ]
DisplayString: <object>
DisplayString: [ 0, -1 .. -1 ]
ViewObj: [ 0, -1 ]
ViewString: [ 0, -1 ]
PrintObj: [ 0, -1 .. -1 ]
Expand Down

0 comments on commit de03049

Please sign in to comment.