Dynamic 将事实追加到现有prolog文件中

Dynamic 将事实追加到现有prolog文件中,dynamic,prolog,sicstus-prolog,prolog-assert,Dynamic,Prolog,Sicstus Prolog,Prolog Assert,在不覆盖原始内容的情况下,我很难将事实插入到现有的Prolog文件中 假设我有一个文件test.pl: :- dynamic born/2. born(john,london). born(tim,manchester). 如果我将其加载到prolog中,并断言更多事实: | ?- assert(born(laura,kent)). yes 我知道我可以通过以下方式来挽救这一局面: |?- tell('test.pl'),listing(born/2),told. 但test.pl现在

在不覆盖原始内容的情况下,我很难将事实插入到现有的Prolog文件中

假设我有一个文件test.pl:

:- dynamic born/2. 

born(john,london).
born(tim,manchester).
如果我将其加载到prolog中,并断言更多事实:

| ?- assert(born(laura,kent)).
yes
我知道我可以通过以下方式来挽救这一局面:

|?- tell('test.pl'),listing(born/2),told.
但test.pl现在只包含事实,而不包含“:-dynamic born/2”:

这是有问题的,因为如果重新加载此文件,我将无法在test.pl中插入更多事实,因为“:-dynamic born/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。这有区别吗


谢谢

它只包含事实并不奇怪,因为这就是你告诉它要保存的全部内容。最简单的方法是使用

|?- tell('test.pl'), write(':- dynamic born/2.'), nl, listing(born/2), told.
或者编写一个小程序来实现这一点。根据您打算如何使用这一点,您可以考虑使用<代码> SAVEEX程序/ 1/2 和<代码>恢复/ 1 < /代码> .<
很抱歉,我无法帮您添加
append/1

我想您应该订阅有问题的答案。或者甚至使用
open/3
close/1
代替过时的
tell
tell
append
对于SWP Prolog,无需直接
编写
born/2
声明。这是通过
清单(born/2)
完成的。非常感谢,这确实有效。我将学习如何使用save_程序和恢复。
|?- tell('test.pl'), write(':- dynamic born/2.'), nl, listing(born/2), told.