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).