[GAP Forum] saved output & SizeScreen?

Frank Lübeck frank.luebeck at math.rwth-aachen.de
Thu Aug 7 00:13:02 BST 2008

On Fri, Aug 01, 2008 at 05:20:02PM -0400, R. Keith Dennis wrote:
> I have two questions:
> How can I turn off "SizeScreen"?  That is, I'd like output to be one
> long line containing no newline characters & no \ .  If I try, for
> example, SizeScreen([10000,]), it gets set to 256.
> gap> SizeScreen([10000,]);;
> gap> SizeScreen();
> [ 256, 28 ]
> I find it a bit strange that I can't find a direct way to simply turn
> of the "for the screen" formatting totally.  I assume that there is one.

Dear Keith, dear Forum,

The values you give to SizeScreen should reflect the actual size of your
terminal in which GAP is running. This info is used in various ways by GAP
for input (if you type in long lines) and output formatting. The current
behaviour of SizeScreen looks sensible to me.

What you are actually asking here is how to print something to any stream 
(file, string stream, the screen, ...) without GAP's line formatting magic.
For this you can use SetPrintFormattingStatus(stream, bool). For example, 
to get something printed to your screen without formatting:

displ := OutputTextUser();
SetPrintFormattingStatus(displ, false);
PrintTo(displ,  13^1313);

But note that just Print(13^1313); will do the formatting, because currently
there is no command in GAP to change the PrintFormattingStatus of the
default output stream that is created during startup. (But I think we can
provide such possibility in future versions of GAP.)

> Also is there a way to remove the spaces from the output?  As far as I
> can tell, if results are read back into gap, omission of spaces causes
> no problems.
If you are using GAP's Print function for, say permutations or lists, these
have their spaces after the commas hard coded. There is no way to change
this behaviour in a running GAP. You can either write your own Print
methods/functions for your objects which print less space characters.

> At the moment I must write a result to a file & use a perl script to
> fix things.  This is surely the wrong way to do it.  Presumably I can
> do it directly in gap, but it seems a bit odd that I can't find a way
> to simply avoid the problems in the first place.  Is there one?

Or you can do what you describe in a similar way in GAP, first do the
printing to a string stream, and use some string manipulation before writing
that string to a file or the screen:

s := ""; 
str := OutputTextString(s, true);
SetPrintFormattingStatus(str, false);
# now print your stuff with PrintTo(str, ...), say
PrintTo(str, Elements(SymmetricGroup(5)));
# now you have everything in the string s, it is in one line, try
# deleting spaces can be done quite efficiently:
RemoveCharacters(s, " ");
# now you can write this to a file, using another quite efficient function:
FileString("myfile", s);

(StringFile and FileString read arbitrary (also binary) files into GAP 
strings and vice versa without any formatting or other processing.)

Let me add two more hints in this context:

If you want to print a huge number of short strings to a file or other
stream, the many PrintTo's or AppendTo's can be a bit inefficient.
Wrapping your printing code in a function and using PrintTo1 can
improve performance considerably.

Another trick in UNIX/Linux environment is to gzip files. If you want to
and there is no myfile.g but a file myfile.g.gz instead, then GAP will
silently read that file and unzip it on the fly.  Files with data where you
want to delete the spaces can probably be compressed by gzip by a huge factor.

I hope that helps, best regards,


///  Dr. Frank Lübeck, Lehrstuhl D für Mathematik, Templergraben 64,  ///
\\\                    52062 Aachen, Germany                          \\\
///  E-mail: Frank.Luebeck at Math.RWTH-Aachen.De                        ///
\\\  WWW:    http://www.math.rwth-aachen.de/~Frank.Luebeck/           \\\

More information about the Forum mailing list