10.4 Operations for Output Streams

  • WriteByte( output-stream, byte ) O

    writes the next character (given as integer) to the output stream output-stream. The function returns true if the write succeeds and fail otherwise.

    WriteByte is the basic operation for input streams. If a WriteByte method is installed for a user-defined type of stream, then all the other output stream operations will work (although possibly not at peak efficiency).

  • WriteLine( output-stream, string ) O

    appends string to output-stream. A final newline is written. The function returns true if the write succeeds and fail otherwise.

    A default method is installed which implements WriteLine by repreated calls to WriteByte.

  • WriteAll( output-stream, string ) O

    appends string to output-stream. No final newline is written. The function returns true if the write succeeds and fail otherwise.

    A default method is installed which implements WriteAll by repreated calls to WriteByte.

    When Printing or appending to a stream (using PrintTo, or AppendTo or when logging to a stream), the kernel generates a call to WriteAll for each line output.

    Example

    gap> str := "";; a := OutputTextString(str,true);;
    gap> WriteByte(a,INT_CHAR('H'));
    true
    gap> WriteLine(a,"allo");
    true
    gap> WriteAll(a,"You\n");
    true
    gap> CloseStream(a);
    gap> Print(str);
    Hallo
    You
    

  • PrintTo( output-stream, arg1, ... )
  • AppendTo( output-stream, arg1, ... )

    These functions work like Print, except that the output is appended to the output stream output-stream.

    Example

    gap> str := "";; a := OutputTextString(str,true);;
    gap> AppendTo( a, (1,2,3), ":", Z(3) );
    gap> CloseStream(a);
    gap> Print( str, "\n" );
    (1,2,3):Z(3)
    

  • LogTo( stream ) F

    LogTo may be used with a stream, just as with a file. See File Operations for details

  • InputLogTo( stream ) O

    InputLogTo may be used with a stream, just as with a file. See File Operations for details

  • OutputLogTo( stream ) O

    OutputLogTo may be used with a stream, just as with a file. See File Operations for details

    When text is being sent to an output text stream via PrintTo, AppendTo, LogTo, etc., it is, by default formatted just as it would be were it being printed to the screen. Thus, it is broken into lines of reasonable length at (where possible) sensible places, lines containing elements of lists or records are indented, and so forth. This is appropriate if the output is eventually to be viewed by a human, and harmless if it to passed as input to GAP, but may be unhelpful if the output is to be passed as input to another program. It is possible to turn off this behaviour for a stream using the SetPrintFormattingStatus operation, and to test whether it is on or off using PrintFormattingStatus.

  • SetPrintFormattingStatus( stream, newstatus ) O

    SetPrintFormattingStatus( stream, newstatus ) sets whether output sent to the stream via PrintTo, AppendTo, etc. (but not WriteByte, WriteLine or WriteAll) will be formatted with line breaks and indentation. If the second argument is true then output will be so formatted, if false then it will not.

  • PrintFormattingStatus( stream ) O

    PrintFormattingStatus( stream ) returns 'true' if output sent to the stream via PrintTo, AppendTo, etc. (but not WriteByte, WriteLine or WriteAll) will be formatted with line breaks and indentation, and false otherwise.

    Example

    gap> s := "";; str := OutputTextString(s,false);;                              
    gap> PrintTo(str,Primes{[1..30]});                                             
    gap> s;
    "[ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,\
     \n  73, 79, 83, 89, 97, 101, 103, 107, 109, 113 ]"
    gap> Print(s,"\n");
    [ 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 ]
    gap> SetPrintFormattingStatus(str, false);
    gap> PrintTo(str,Primes{[1..30]});
    gap> s;
    "[ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,\
     \n  73, 79, 83, 89, 97, 101, 103, 107, 109, 113 ][ 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 ]"
    gap> Print(s,"\n");
    [ 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 ][ 2, 3, 5, 7, 11, 13, 17, 19, 2\
    3, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 1\
    07, 109, 113 ]
    gap> 
    

    [Top] [Previous] [Up] [Next] [Index]

    GAP 4 manual
    February 2000