next up previous contents index
Next: Plotting Functions Up: Functions with Side Effects Previous: Functions with Side Effects

Input and Output Routines

Of the functions listed in this section, only print_char, print_string,write_char, write_string, and write_check can be called in parallel.

print_char(v) {char tex2html_wrap_inline10612 bool}
  Prints a character to standard output.

print_string(v) {[char] tex2html_wrap_inline10614 bool}
  Prints a character string to standard output.

write_object_to_file(object, filename) {(a, [char]) tex2html_wrap_inline10616 bool :: (a in any)}
  Writes an object to a file. The first argument is the object and the second argument is a filename. For example write_object_to_file([2,3,1,0],"/tmp/foo") would write a vector of integers to the file /tmp/foo. The data is stored in an internal format and can only be read back using read_object_from_file.

write_string_to_file(a, filename) {([char], [char]) tex2html_wrap_inline10618 bool}
  Writes a character string to the file named filename.

append_string_to_file(a, filename) {([char], [char]) tex2html_wrap_inline10620 bool}
  Appends a character string to the file named filename.

read_object_from_file(object_type, filename) {(a, [char]) tex2html_wrap_inline10622 a :: (a in any)}
  Reads an object from a file. The first argument is an object of the same type as the object to be read, and the second argument is a filename. For example, the call read_object_from_file(0,"/tmp/foo") would read an integer from the file /tmp/foo, and read_object_from_file([] int,"/tmp/bar") would read a vector of integers from the file /tmp/foo. The object needs to have been stored using the function write_object_to_file.

read_string_from_file(filename) {[char] tex2html_wrap_inline10624 [char]}
  Reads a whole file into a character string.

read_int_seq_from_file(filename) {[char] tex2html_wrap_inline10626 [int]}
  Reads a sequence of integers from the file named filename. The file must start with a left parenthesis, contain the integers separated by either white spaces, newlines or tabs, and end with a right parenthesis. For example:

( 22 33 11
10   14
12 11 )
represents the sequence [22, 33, 11, 10, 14, 12, 11].

read_float_seq_from_file(filename) {[char] tex2html_wrap_inline10628 [float]}
  Reads a sequence of floats from the file named filename. The file must start with a left parenthesis, contain the floats separated by either white spaces, newlines or tabs, and end with a right parenthesis. The file may contain integers (no .); these will be coerced to floats.

open_in_file(filename) {[char] tex2html_wrap_inline10630 (stream, bool, [char])}
  Opens a file for reading and returns a stream for that file along with an error flag and an error message.

open_out_file(filename) {[char] tex2html_wrap_inline10632 (stream, bool, [char])}
  Opens a file for writing and returns a stream for that file along with an error flag and an error message. File pointers cannot be returned to top-level. They must be used within a single top-level call.

close_file(str) {stream tex2html_wrap_inline10634 (bool, [char])}
  Closes a file given a stream. It returns an error flag and an error message.

write_char(a, stream) {(char, stream) tex2html_wrap_inline10636 (bool, [char])}
  Prints a character to the stream specified by stream. It returns an error flag and error message.

write_string(a, stream) {([char], stream) tex2html_wrap_inline10638 (bool, [char])}
  Prints a character string to the stream specified by stream. It returns an error flag and error message.

read_char(stream) {stream tex2html_wrap_inline10640 (char, bool, [char])}
  Reads a character from stream. If the end-of-file is reached, the null character is returned along with the success flag set to false.

read_string(delim, maxlen, stream)
{([char], int, stream) tex2html_wrap_inline10642 (([char], int), bool, [char])}
  Reads a string from the stream stream. It will read until one of the following is true (whichever comes first):

  1. the end-of-file is reached,
  2. one of the characters in the character array delim is reached,
  3. maxlen characters have been read.
If maxlen is negative, then it is considered to be infinity. The delim character array can be empty.

read_line(stream) {stream tex2html_wrap_inline10644 (([char], bool), bool, [char])}
  Reads all the characters in stream up to a newline or the end-of-file (whichever comes first). The newline is consumed and not returned. As well as returning the line, it returns a boolean flag indicating whether reading was terminated on a newline (f) or EOF (t).

read_word(stream) {stream tex2html_wrap_inline10646 (([char], char, bool), bool, [char])}
  Reads all the characters in stream up to a newline, space, tab or the end-of-file (whichever comes first). The newline, space or tab is consumed and not returned. As well as returning the line, it returns a (char,bool) pair that indicates on what character the word was terminated and whether it was terminated on a EOF (the bool is t).

open_check(str, flag, err_message) {(a, bool, [char]) tex2html_wrap_inline10648 a :: (a in any)}
  Checks if an open on a file succeeded and prints an error message if it did not. For example, in the form open_check(open_in_file("/usr/foo/bar")), if the open is successful it will return a stream, otherwise it will print an error message and return the null stream.

write_check(flag, err_message) {(bool, [char]) tex2html_wrap_inline10650 bool}
  Checks if a write succeeded and prints an error message if it did not. For example, in the form write_check(write_string("foo",stream)), if the write is successful it will return t, otherwise it will print an error message and return f.

read_check(val, flag, err_message) {(a, bool, [char]) tex2html_wrap_inline10652 a :: (a in any)}
  Checks if a read succeeded and prints an error message if it did not. It also strips off the error information from the read functions. For example, in the form read_check(read_char(stream)), if the read is successful it will return the character which is read, otherwise it will print an error message.

close_check(flag, err_message) {(bool, [char]) tex2html_wrap_inline10654 bool}
  Checks if a close on a stream succeeded and prints an error message if it did not. For example, in the form close_check(close_file(stream)), if the close is successful it will return t, otherwise it will print an error message and return f.

nullstr {stream}
  The null stream.

stdin {stream}
  The standard input stream.

stdout {stream}
  The standard output stream.

stderr {stream}
  The standard error stream.



next up previous contents index
Next: Plotting Functions Up: Functions with Side Effects Previous: Functions with Side Effects



Jonathan Hardwick
Tue Nov 28 13:57:00 EST 1995