How do I parse the 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 normal predicates (not DCG) and using built-ins like get_char/2
and read_line_to_codes/2
, but at the end the implementation looks suspiciously similar to the solution I would have written in C.
And if I can sneak a very much related question: what is standard input in SWI-Prolog? read_line_to_codes
(library(readutil)
) needs 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 am I going to know which one is the standard input of the operating system (Linux in my case)?