我无法将事实插入现有的 Prolog 文件,而不会覆盖原始内容。
假设我有一个文件 test.pl:
:- dynamic born/2.
born(john,london).
born(tim,manchester).
如果我在序言中加载它,并且我断言更多事实:
| ?- assert(born(laura,kent)).
yes
我知道我可以通过以下方式保存它:
|?- tell('test.pl'),listing(born/2),told.
哪个有效,但 test.pl 现在只包含事实,而不是“:-动态出生/2”:
born(john,london).
born(tim,manchester).
born(laura,kent).
这是有问题的,因为如果我重新加载此文件,我将无法再将事实插入 test.pl,因为“:-动态出生/2”。不存在了。
我在某处读到,我可以这样做:
append('test.pl'),listing(born/2),told.
这应该只是附加到文件的末尾,但是,我收到以下错误:
! Existence error in user:append/1
! procedure user:append/1 does not exist
! goal: user:append('test.pl')
顺便说一句,我正在使用 Sicstus prolog。这有什么不同吗?
谢谢!