next up previous contents
Next: Int Up: Basic Classes Previous: Object   Contents

IO

The IO class provides the following methods for performing simple input and output operations:
out_string(x : String) : SELF_TYPE
out_int(x : Int) : SELF_TYPE
in_string() : String
in_int() : Int
The methods out_string and out_int print their argument, flush the standard output, and return their self parameter.

The interpreter or compiler changes every \t to a tab and every \n to a newline in the argument x to out_string before emitting the resulting string. Note that this is different from normal escape sequence handling, where \n would be a single character stored in the string. In Cool, it is two characters, but out_string prints a newline instead of \n.

The method in_string reads a string from the standard input, up to but not including a newline character or the end of file. The newline character is consumed but is not made part of the returned string. If an error occurs then in_string returns "", the string of length 0. Note that while literal lexical string constants are limited to size 1024, strings generated by in_string (or String.concat, etc.) can be of arbitrary size. There is no special processing of the two-character sequences \t or \n (or, indeed \anything) during in_string. Errors include:

The method in_int reads a single possibly-signed integer, which may be preceded by whitespace. Any characters following the integer, up to and including the next newline, are discarded by in_int. If an error occurs then in_int returns 0. Errors include:

A class can make use of the methods in the IO class by inheriting from IO. It is an error to redefine the IO class.