I am studying Prolog using SWI-Prolog.
I am finding some problems with the following example that simply access to a file and write in it what the user put in the Prolog Shell.
processFile(File) :- see(File),
processFile,
seen.
processFile :- read(Query),
process(Query).
process(end_of_file) :- !.
process(Query) :- Query,
write(Query),
nl,
processFile.
The problem is that when, in the Prolog shell, I try to execute the processFile statement with a file name I obtain an error:
If I give a file name with an extension I obtain this error message (seems to interpret the extension as an operator):
7 ?- processFile(myFile.txt).
ERROR: Syntax error: Operator expected
ERROR: processFile(myFile
ERROR: ** here **
ERROR: .txt) .
If I give a file name without extension I obtain this other error message (the file don't exist):
7 ?- processFile(myFile).
ERROR: see/1: source_sink `myFile' does not exist (No such file or directory)
So I have also try to create a new file named myFile (without extension) in the same folder where is the prolog source code file but I still again obtain:
8 ?- processFile(myFile).
ERROR: see/1: source_sink `myFile' does not exist (No such file or directory)
Why? where is the error? How can I solve it?