Prolog: get vs. at_end_of_stream to check end of file

I read the file using the prolog and wondered about the difference in the statement:

processRead(Stream, ...) :- at_end_of_stream(Stream), !.

and

processRead(Stream, ...) :- get(Stream, Ch), Ch is -1, !.

Whether there is a?

+4
source share
3 answers
First things first! Follow @mat tips !

If you need to choose, always prefer to useat_end_of_stream/1 over get/2!

+3

, .

SWI-Prolog :

: DCG , . . .. ..

+3

( ) at_end_of_stream/1. , .. (, , - , get_code/2), , .

  • , , , () EOF .

  • at_end_of_stream/1 , ( ). , , , , . SICStus Prolog at_end_of_stream/1 , at_end_of_stream/1 .

, , , .

+1

Source: https://habr.com/ru/post/1624445/


All Articles