Prolog - ASSERT and RETRACT

让人想犯罪 __ 提交于 2019-11-27 20:29:33

I can suggest you a very simple way of doing this.

1 ?- assert(a(1)).
true.

2 ?- assert(a(2)).
true.

3 ?- assert(a(3)).
true.

4 ?- a(A).
A = 1 ;
A = 2 ;
A = 3.

5 ?- tell('a_db.txt'), listing(a), told.
true.

Then close session, reopen.

1 ?- a(A).
ERROR: toplevel: Undefined procedure: a/1 (DWIM could not correct goal)
2 ?- ['a_db.txt'].
% a_db.txt compiled 0.00 sec, 516 bytes
true.

3 ?- a(A).
A = 1 ;
A = 2 ;
A = 3.

4 ?- listing(a).
:- dynamic a/1.

a(1).
a(2).
a(3).

true.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!