Problems storing facts in Prolog

I'm a little new to Prolog and I use SWI-Prolog v6.6 to store in my * .pl file.

:- dynamic fact/2.

assert(fact(fact1,fact2)).

With the above code, I can make statements, and it works fine, but the problem is when I close SWI-Prolog and I open the * .pl file again, the statements I made are gone ...

Is there a way to make statements and they will be saved even if I close SWI-Prolog?

Sorry for my bad english and thanks! (

+1
source share
2 answers

Saving state has certain limitations , also see the recent discussion on the SWI-Prolog mailing list.

, SWI-Prolog - persistency. :

:- use_module(library(persistency)).

:- persistent fact(fact1:any, fact2:any).

:- initialization(init).

init:-
  absolute_file_name('fact.db', File, [access(write)]),
  db_attach(File, []).

/ , assert_fact/2, retract_fact/2 retractall_fact/2.

Prolog fact.db.

:

$ swipl my_facts.pl
?- assert_fact(some(fact), some(other,fact)).
true.
?- halt.
$ swipl my_facts.pl
?- fact(X, Y).
X = some(fact),
Y = some(other, fact).
+3

, , mbratch . , qsave_program/2. swi docs, qsave_program(+File, +Options)

File. , , Prolog .

http://www.swi-prolog.org/pldoc/man?section=runtime

+1

Source: https://habr.com/ru/post/1691991/


All Articles