SWI Prolog Read Input Stream Error

I'm redirectioning the user input to a file see('entradasaida.txt'). That works good. Although, when I try to read from that stream input file swi gives me this error:

ERROR: entradasaida.txt:3:0: Syntax error: Operator expected.

Why? How can I fix this error?

liste(A) :-
    see(A),
    nl,
    read(B),
    escreva(B),
    seen.

escreva(A) :-
    write(A),
    nl,
    A==end-of-file, !.

escreva(_) :-
    read(A),
    escreva(A).


18 ?- liste('entradasaida.txt').
ERROR: entradasaida.txt:2:0: Syntax error: Operator expected
19 ?- trace.
true.

[trace] 19 ?- liste('entradasaida.txt').
   Call: (6) liste('entradasaida.txt') ? creep
   Call: (7) see('entradasaida.txt') ? creep
   Exit: (7) see('entradasaida.txt') ? creep
   Call: (7) nl ? creep

   Exit: (7) nl ? creep
   Call: (7) read(_G627) ? creep
ERROR: entradasaida.txt:3:0: Syntax error: Operator expected
   Exception: (7) read(_G648) ? creep
Exception: (6) liste('entradasaida.txt') ? creep

Upvotes: 0

Views: 1878

Answers (1)

I found my mistake. The file entradasaida.txt contains some lines that doesn't end with a period ('.'). So, the read command reacts with that message (ERROR: entradasaida.txt:2:0: Syntax error: Operator expected).

Upvotes: 1

Related Questions