diff --git a/lib/list.gi b/lib/list.gi index 50f3cbc212..e2cce07929 100644 --- a/lib/list.gi +++ b/lib/list.gi @@ -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 ], @@ -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 ) @@ -3857,7 +3885,7 @@ function( list ) end ); InstallMethod( ViewObj, - "for ranges", + "for a range", [ IsList and IsFinite and IsRange ], function( list ) Print( "[ " ); diff --git a/tst/testinstall/range.tst b/tst/testinstall/range.tst index f72777957a..a28abb3854 100644 --- a/tst/testinstall/range.tst +++ b/tst/testinstall/range.tst @@ -40,7 +40,7 @@ gap> TestPrintRangeRep:=function(r) # gap> TestPrintRangeRep([0..1]); Display: [ 0 .. 1 ] -DisplayString: +DisplayString: [ 0 .. 1 ] ViewObj: [ 0, 1 ] ViewString: [ 0, 1 ] PrintObj: [ 0 .. 1 ] @@ -48,31 +48,31 @@ PrintString: [ 0 .. 1 ] String: [ 0 .. 1 ] gap> TestPrintRangeRep([0..2]); Display: [ 0 .. 2 ] -DisplayString: +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: +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: +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: +DisplayString: [ 0, -1 .. -1 ] ViewObj: [ 0, -1 ] ViewString: [ 0, -1 ] PrintObj: [ 0, -1 .. -1 ]