-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions to View, Display, and Code (formerly Print) to a stream
- Loading branch information
Showing
4 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
############################################################################# | ||
## | ||
#W show.gd | ||
## | ||
## Contains the declarations of operations used for outputting objects | ||
## to streams | ||
## | ||
|
||
############################################################################ | ||
## | ||
#O ViewObjStream(<stream>, <obj>) | ||
## | ||
## <ManSection> | ||
## <Oper Name="ViewObjStream" Arg='stream, obj'/> | ||
## | ||
## <Description> | ||
## <Ref Oper="ViewObjStream"/> prints information about the object <A>obj</A> | ||
## to the stream <A>stream</A>. | ||
## This information should be concise and human readable, | ||
## in particular <E>not</E> necessarily detailed enough for defining <A>obj</A>, | ||
## an in general <E>not</E> &GAP; readable. | ||
## <P/> | ||
## More detailed information can be obtained by <Ref Func="ShowObj"/> | ||
## </Description> | ||
## </ManSection> | ||
## | ||
DeclareOperation("ViewObjStream", [IsOutputStream, IsObject]); | ||
|
||
############################################################################ | ||
## | ||
#O DisplayObjStream(<stream>, <obj>) | ||
## | ||
## <ManSection> | ||
## <Oper Name="DisplayObjStream" Arg='stream, obj'/> | ||
## | ||
## <Description> | ||
## <Ref Oper="DisplayObjStream"/> prints information about the object | ||
## <A>obj</A> to the stream <A>stream</A> in a nicely formatted way. | ||
## <P/> | ||
## More detailed information can be obtained by <Ref Func="ShowObj"/> | ||
## </Description> | ||
## </ManSection> | ||
## Nicely formatted output | ||
## | ||
DeclareOperation("DisplayObjStream", [IsOutputStream, IsObject]); | ||
|
||
############################################################################ | ||
## | ||
#O CodeObjStream(<stream>, <obj>) | ||
## | ||
## <ManSection> | ||
## <Oper Name="CodeObjStream" Arg='stream, obj'/> | ||
## | ||
## <Description> | ||
## <Ref Oper="CodeObjStream"/> prints GAP code to recreate the object | ||
## <A>obj</A> to the stream <A>stream</A>. | ||
## <P/> | ||
## More detailed information can be obtained by <Ref Func="ShowObj"/> | ||
## </Description> | ||
## </ManSection> | ||
## | ||
DeclareOperation("CodeObjStream", [IsOutputStream, IsObject]); | ||
|
||
############################################################################ | ||
## | ||
#E | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
############################################################################# | ||
## | ||
#W show.gi | ||
## | ||
## Contains implementations of standard functions for outputting objects | ||
## to streams. | ||
## | ||
## These functions should replace all the View/Print/Display variants, and | ||
## in particular get rid of a lot of code duplication, when there are separate | ||
## implementations for View and ViewString for instance, and lack of | ||
## implementations when View exists, but ViewString doesn't (probably for the | ||
## reason above) | ||
## | ||
## output streams will be free to ignore/strip formatting helpers | ||
## | ||
## The naming is still topic of discussion. I renamed Print to Code, because | ||
## this makes the requirement to output Code clearer. | ||
## | ||
|
||
############################################################################ | ||
## | ||
#O ViewObjStream(<stream>, <obj>) | ||
## | ||
InstallMethod(ViewObjStream, "for an output stream, and an object", | ||
[IsOutputStream, IsObject], | ||
function(stream, obj) | ||
PrintTo(stream, ViewString(obj)); | ||
end); | ||
|
||
# A possible implementation for ViewString | ||
# (once ViewObjStream is the default) | ||
NewViewString := function(obj) | ||
local res, stream; | ||
res := ""; | ||
stream := OutputTextString(res, true); | ||
ViewObjStream(stream, obj); | ||
return res; | ||
end; | ||
|
||
# A possible implementation for View if ViewObjStream has a method installed | ||
NewView := function(obj) | ||
local stream; | ||
stream := OutputTextFile("*stdout*", true); | ||
ViewObjStream(stream, obj); | ||
end; | ||
|
||
############################################################################ | ||
## | ||
#O DisplayObjStream(<stream>, <obj>) | ||
## | ||
InstallMethod(DisplayObjStream, "for an output stream, and an object", | ||
[IsOutputStream, IsObject], | ||
function(stream, obj) | ||
PrintTo(stream, DisplayString(obj)); | ||
end); | ||
|
||
############################################################################ | ||
## | ||
#O CodeObjStream(<stream>, <obj>) | ||
## | ||
InstallMethod(CodeObjStream, "for an output stream, and an object", | ||
[IsOutputStream, IsObject], | ||
function(stream, obj) | ||
PrintTo(stream, String(obj)); | ||
end); | ||
|
||
############################################################################ | ||
## | ||
#E | ||
|