How to parse standard input (without buffering)? If I understand correctly, phrase/2 needs a list, and phrase_from_file/2 from library(pure_input) needs a file.
I solved my problem using regular predicates (not DCG) and using built-in functions like get_char/2 and read_line_to_codes/2 , but at the end the implementation looks suspiciously similar to the solution I would write in C.
And if I can sneak up a very close question: what is standard input in SWI-Prolog? read_line_to_codes ( library(readutil) ) requires an input stream (unlike get/1 , for example). I get it with the following predicate:
input_stream(Stream) :- current_stream(Object, read, Stream), integer(Object).
. which, of course, works, but feels a bit hacked. Is it possible to have more than one open input stream? How do I know which one is the standard input of the operating system (Linux in my case)?
user1812457
source share