I would like to understand GAP's behaviour when I launch a script from the command line, for example
$ gap mytest.gap
as opposed to calling it from inside GAP
gap> Read("mytest.gap");
In particular, I've tried to suppress automatic formatting with line breaks and indentation. If the file mytest.gap
is the following
SetPrintFormattingStatus( "*stdout*", false );
Print( Primes{[1..30]}, "\n" );
then I get the expected behaviour when calling it with Read()
, namely
[ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113 ]
whereas launching it from the command line, I still get
[ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101, 103, 107, 109, 113 ]
Can somebody please give an explanation for this behaviour? Is GAP's treatment of scripts launched from a command line invocation documented somewhere? I couldn't find it in the manual, but the man page does say usage: gap [OPTIONS] [FILES]
with documentation only of how the options are treated.
I am afraid that it is currently not possible to completely disable the output formatting of Print
the way you tried.
However, you can work around the problem by using the newer stream APIs and PrintTo
, like this:
s:=OutputTextUser();
SetPrintFormattingStatus( s, false );
PrintTo( s, Primes{[1..30]}, "\n" );
I logged this as a bug in the GAP issue tracker, and perhaps we can fix it in the next release (or perhaps somebody will explain why it's "not a bug but a feature" ;-).