There are three areas that require special attention when using qsave_program/[1,2].
:- goal.
lines) that
perform other actions than setting predicate attributes (dynamic/1, volatile/1,
etc.) or loading files (use_module/1,
etc.). Goals that need to be executed when the state is started must use initialization/1
(ISO standard) or initialization/2
(SWI extension that provides more control over when the goal is
executed). For example, initialization/2
can be used to start the application:
:- initialization(go, main).
The volatile/1 directive may be used to prevent saving the clauses of predicates that hold such references. The saved program must reinitialise such references using the normal program initialization techniques: use initialization/1,2 directives, explicitly create them by the entry point or make the various components recreate the contextx lazily when required.