Prolog:将文本添加到文件末尾
我想在序言中将文本添加到数据库中。类似于
adding :- tell('a.txt'), write('abc'), told.
但不覆盖a.txt。我尝试过像这样使用附加:
append('a.txt'),write('abc'), told.
但它不起作用。侦听器只需给出“否”响应,并且文件不会更改。 顺便说一句,我正在使用 Amzi Prolog。
任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须使用这些 IO 谓词:open/3、write/2、close/1。
检查此处
You have to use these IO predicates: open/3, write/2, close/1.
Check here
在 SWI-Prolog 中,这是可行的:
也许 Amzi Prolog 没有
append/1
,这会导致失败而不是异常。或者该文件可能不可写(这会导致失败,而不是异常)。In SWI-Prolog this works:
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).