I want to add text to a database in prolog. Something like
adding :- tell('a.txt'), write('abc'), told.
but not overwriting the a.txt. I've tried using append like 开发者_开发问答this:
append('a.txt'),write('abc'), told.
but it didn't work. The listener just give a 'no' response and file is not changed. I'm using Amzi Prolog, btw.
Any help will be appreciated.
You have to use these IO predicates: open/3, write/2, close/1.
adding :- open('a.txt', append, Handle), write(Handle, 'abc'), close(Handle).
Check here
In SWI-Prolog this works:
?- append('a.txt'), write('abc'), told.
true.
?- append('a.txt'), write('abc'), told.
true.
Maybe Amzi Prolog does not have append/1
and this causes failure rather than an exception. Or maybe the file is not writable (and this causes failure, rather than an exception).
精彩评论