Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog: get vs. at_end_of_stream for checking end of file

Tags:

file

eof

prolog

I am reading a file using prolog and was wondering about the difference of saying:

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

and:

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

Is there any?

like image 290
今天春天 Avatar asked Feb 08 '23 00:02

今天春天


1 Answers

First things first! Follow @mat's advice!

If you need to chose, always prefer using at_end_of_stream/1 over get/2!

  • get/2 is deprecated. If you have decade-old legacy code, migrate it.

    If your code is new, don't ever use it. Never. Not even once.

  • at_end_of_stream/1 is defined by the iso-prolog standard.
  • Virtually every modern Prolog processor supports at_end_of_stream/1—including (but not limited to) GNU Prolog, SICStus Prolog, SWI Prolog, B-Prolog, and Eclipse CLP.
like image 86
repeat Avatar answered Feb 16 '23 03:02

repeat