Analysis from standard input

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)?

+6
source share
1 answer

I think you are looking for the correct thread name. Here is an example that might be useful:

 ?- read_line_to_codes(user_input,L). |: a line L = [97, 32, 108, 105, 110, 101]. 

The most detailed description page I have found is here .

+2
source

All Articles