Can't access to a file in Prolog, always read the end_of_file atom -


i studying prolog using swi prolog , finding difficulties related operation of reading , writing on file.

i have simple program read standard input (the keyboard) , write on file:

processfile(file) :- see(file),                  processfile,                  seen.  processfile :- read(query),                process(query).  process(end_of_file) :- !.  process(query) :- query,                   write(query),               nl,               processfile. 

i trying execute under linux. in bash go folder located prolog source file , myfile file and, after have consult program, execute following statment:

?- processfile(myfile). true. 

as can see probem give me true can't insert keyboard, write myfile file.

if try trace happen obtain following informations:

[trace]  ?- processfile(myfile).    call: (6) processfile(myfile) ? creep    call: (7) see(myfile) ? creep    exit: (7) see(myfile) ? creep    call: (7) processfile ? creep    call: (8) read(_g697) ? creep    exit: (8) read(end_of_file) ? creep    call: (8) process(end_of_file) ? creep    exit: (8) process(end_of_file) ? creep    exit: (7) processfile ? creep    call: (7) seen ? creep    exit: (7) seen ? creep    exit: (6) processfile(myfile) ? creep true. 

as can see can access myfile file, , correctly ask processfile predicate contain read statment seems automatically read end_of_file atom , can't go on.

why? can solve , write file?

you must use tell/1 write in file, told revert previous. using see/1 you're reading that, , it's empty...

but iso io better...


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -