Recent Changes - Search:

PmWiki

pmwiki.org

edit SideBar

IsoIo

I/O built-ins and EOF

According to ISO 13211-1, input streams have an end_of_stream property, which can take the values not, at and past.

It also defines the stream option eof_action(...) in section 7.10.2.11. The name is misleading, as it actually specifies the behaviour when the stream is past (rather than at) eof:

error
raise permission_error(input,past_end_of_stream,Stream)
eof_code
behave as if at eof
reset
re-check the source for new input that may cause it not to be at eof any longer

The default is implementation-defined, possibly different for different streams. In ECLiPSe, error (files, string streams) or reset (tty, pipes, sockets, queues and null).

ECLiPSe actually closes the stream after reporting the past_end_of_stream error.

predicatenot eofat eofpast eof [error]past eof [eof_code]past eof [reset]
get_code/2last char-1error-1new char
read/2last termend_of_fileerrorend_of_filenew term
read_string/4last stringfailserrorfailsnew string
read_string/5string,-1n/aerror"",-1new string, new sep
read_string/3last string?error?new string

It seems to make sense for read_string/5 to leave the stream in past-eof position when -1 was returned as the separator.

For read_string/3, if the stream contains less characters than requested, should it leave the stream at or past eof? As no separator is consumed in this case, it should be at. Reading from a stream in at-eof position could return "" or fail (as read_string/4 does).

EDIT 2019: It is more convenient for read_string/3,5 to once return "",-1 at eof.

Edit - History - Print - Recent Changes - Search
Page last modified on September 04, 2019, at 05:42 PM