【发布时间】:2010-05-27 14:19:56
【问题描述】:
我在将事实插入现有 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。这有什么不同吗?
谢谢!
【问题讨论】:
-
我认为您应该订阅有问题的答案assert fact into file in prolog。甚至Prolog - ASSERT and RETRACT
-
使用
open/3和close/1代替过时的tell、told、append
标签: dynamic prolog sicstus-prolog prolog-assert