title: how to read a file in prolog?
body: <p>I want to read a text file like <code>test.txt</code>:</p>
  
  <pre><code>birthbook(tom,9,1).
  birthbook(add,9,1).
  birthbook(ddd,8,1).
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>test:-
    open('test.txt', read, Str),
    read_file(Str,Lines),
    close(Str),
    write(Lines), nl.
  
  read_file(Stream,[]) :-
    at_end_of_stream(Stream).
  read_file(Stream,[X|L]) :-
    \+ at_end_of_stream(Stream),
    read(Stream,X),
    read_file(Stream,L).
  </code></pre>
  
  <p>However, it shows that 
  ERROR: test.txt:1:4: Syntax error: Unexpected end of file.</p>