Processing math: 46%

Previous Up Next

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 \rm \LQT \RQT, the string of length 0. Note that while literal lexical string constants are limited to size 1024, strings generated by \rm in\_string (or \rm String.concat, etc.) can be of arbitrary size. There is no special processing of the two-character sequences \rm \backslash t or \rm \backslash n (or, indeed \it \backslash anything) during \rm in\_string. Errors include:

The method \rm 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 \rm in\_int. If an error occurs then \rm in\_int returns 0. Errors include:

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

Previous Up Next