I’m using: SWI-Prolog version 9.0.4 for x86_64-linux
I want the code to: read lines of STDIN until EOF into a single list.
But what I’m getting is:
$ echo -e "hi\nthere" | swipl thing.pl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.0.4)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
ERROR: Stream user_input:8:5 Syntax error: Unexpected end of file
% halt
I attempted using bagof/3 to collect all the possible values of S into a list but that didn’t work as well.
Did you see the example code under the docs for read_string/5? It says “backtrack over lines in a file”. If you took that you could maybe use it with bagof/3, like this:
Please note that there are many small things that could be done differently. This was now just the lowest effort, meaning I just copy-pasted the example code and ran it.