How do I read in a text file and print them out to a file in Prolog?
问题 I have a text file, and I want to read it in and print them out in screen and write them into a new output file. So what I have done so far is main :- open('text.txt', read, ID), % open a stream repeat, % try again forever read(ID, X), % read from the stream write(X), nl, % write to current output stream X == end_of_file, % fail (backtrack) if not end of !, close(ID). But I only received an error message like, ERROR: text.txt:1:0: Syntax error: Operator expected What should I do? 回答1: read/2