Path: utzoo!mnetor!uunet!mcvax!prlb2!kulcs!bimandre From: bimandre@kulcs.uucp (Andre Marien) Newsgroups: comp.lang.prolog Subject: behavior of read/get0 at end_of_file Message-ID: <1197@kulcs.kulcs.uucp> Date: 16 Mar 88 10:24:05 GMT References: 608 Reply-To: bimandre@kulcs.UUCP () Organization: Katholieke Universiteit Leuven, Dept. Computer Science Lines: 50 Keywords: get0 read end_of_file > copy_chars :- > get0(Char), > copy_chars(Char). > > copy_chars(-1) :- !. > copy_chars(Char) :- > put(Char), > copy_chars. At the benchmark workshop he agitated vividly against the different behavior of BIM_Prolog in case of end of file. BIM_Prolog fails when get0 attemps to read past end of file in stead of returning -1. The same is true for read. If you write the same program as above with the BIM_prolog convention, this it what it looks like : copy_chars :- get0(Char), !, put(Char), copy_chars. copy_chars . The previous code creates a choicepoint for every character which get processed. It can be easily avoided : copy_chars :- copy_chars_h. copy_chars . copy_chars_h :- get0(Char), put(Char), copy_chars_h . Now this looks so obviously better and more readable to me, that it convinces me we made the better choice. BTW, if you ever want to convert a program with a different interpretation, the solution is easy : /*QP*/read(X) :- /*bim*/read(X), ! . /*QP*/read(whatever_is_used_to_indicate_end_of_file) . Of course, as you can verify above, a different coding may very well produce a better program. Andre' Marien B.I.M. Belgium bimandre@kulcs Bart Demoen K.U.Leuven Belgium bimbart@kulcs