StdIO: Standard Input/Output

      $channel StdIn StdOut StdErr;

StdIn, StdOut, and StdErr are the standard input/output channels, which are automatically opened before the program execution starts, and automatically closed after the program execution has terminated.

      $func Channel = s.Channel;

Channel creates a new channel s.Channel.

      $func? OpenFile      s.Channel e.FileName s.Mode = ;
      $func  CloseChannel  s.Channel = ;

OpenFile opens the channel s.Channel and associates it with the file having the name e.FileName. s.Mode is a word symbol specifying the mode in which the file is to be dealt with: "r" or "R" indicates that data are to be read from the file, "w" or "W" that data are to be written to the file, "a" or "A" that data are to be appended to the existing file. If the file cannot be opened, OpenFile returns $fail(0).

CloseChannel closes the channel s.Channel.

      $func? IsEof  s.Channel = ;

IsEof tests whether the current position in the file associated with the channel s.Channel is at the end of the file.

      $func? Read      = t.Term;
      $func? ReadChar  = s.Char;
      $func? ReadLine  = e.Char;
      $func  Write     e.Exp = ;
      $func  WriteLn   e.Exp = ;
      $func  Print     e.Exp = ;
      $func  PrintLn   e.Exp = ;

Read reads the current character representation of a ground term from the channel &StdIn. If there is no term to be read, the function returns $fail(0).

ReadChar reads the current character from the channel &StdIn. If there is no character to be read, the function returns $fail(0).

ReadLine reads the characters from the channel &StdIn up to the nearest newline character (inclusive), and returns the characters as the result (not including the newline character). If there is no character to be read, the function returns $fail(0).

Write writes the character representation of the expression e.Exp to the channel &StdOut (if e.Exp does not contain dynamic symbols, the terms comprising the expression can later be read back by the function Read).

WriteLn works in the same way as Write does, except that it adds a newline character to the end of the expression's representation.

Print converts the expression e.Exp to a character sequence in the way the function ToChars does, and writes this sequence to the channel &StdOut.

PrintLn works in the same way as Print does, except that it adds a newline character to the end of the character sequence.

      $func? ReadCh      s.Channel = t.Term;
      $func? ReadCharCh  s.Channel = s.Char;
      $func? ReadLineCh  s.Channel = e.Char;
      $func  WriteCh     s.Channel e.Exp = ;
      $func  WriteLnCh   s.Channel e.Exp = ;
      $func  PrintCh     s.Channel e.Exp = ;
      $func  PrintLnCh   s.Channel e.Exp = ;

These functions work in the same way as the corresponding functions without "Ch" do, except that the operations are performed on the channel s.Channel.