Discussions related to Visual Prolog
billgates198606

UNexpected end of file when use inputStream::endOfStream/0

Unread post by billgates198606 »

Code: Select all

addterm(Filename):-       mydb := chainDB::db_open("c:\\mydatabase2.db",chainDB::in_file),         mydb:bt_open("booktree",Selector),      selector:=Selector,       InputFilestream = inputStream_file::openFile8(Filename),     repeat(),   String=InputFilestream:readline(),       hasdomain(term,Term),     console::write("addterm"),        conversion5x::term_str(Term,String),        mydb:chain_inserta(Filename,Term,Ref),        Term=tm(_Fname,_Path,Kwords,_Topic),        mydb:key_insert(selector,Kwords,Ref),          console::write(Term),          inputStream::endOfStream,              InputFilestream:close(),     console::write("close db"),      mydb:db_close(),         mydb:bt_close(selector),           mydb := erroneous.
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

The code you have written cannot possible give the mentioned error, because that code cannot compile.

The line

Code: Select all

inputStream::endOfStream
does not make sense.

I expect that you actually mean:

Code: Select all

InputFilestream:endOfStream()
You should notice that repeat will still give a backtrack possibility, so if you later fail somewhere you will come back to repeat and try to read yet another line this time from a closed file.

So you should "cut" away backtracking as soon as you reach the end of the stream:

Code: Select all

InputFilestream:endOfStream(), !, % don't backtrack to repeat anymore
Regards Thomas Linder Puls
PDC
Post Reply