11.3.194 save_program/[1,2]

Synopsis

save_program(+File)

save_program(+File, +Goal)

Saves the state of the current execution in object format to File. A goal, Goal, to be called upon execution/restoring of the saved state, may be specified.

Arguments

File
file_spec, must be ground

A file specification, ‘.sav’ extension optional.

:Goal
callable, must be nonvar

A goal, defaults to true.

Description

save_program/[1,2] creates a binary representation of all predicates in all modules existing in the system. However, it does not save the user's pre-linked code. It also saves such states of the system as operator definitions, Prolog flags, debugging and advice state, initializations, and dependencies on foreign resources.

The resulting file can be restored using restore/1.

Any unbound variables in Goal with attributes or blocked goals attached to them will be replaced by plain, brand new variables. This is analogous to the way attributed variables are handled in terms that are written, copied, asserted, gathered as solutions to findall/3 and friends, or raised as exceptions. To retain the attributes, you can use copy_term/3 (see ref-lte-cpt).

Exceptions

instantiation_error
File or Goal is not bound.
type_error
File is not a valid file specification, or Goal is not a callable.
permission_error
File is not writable.

Examples

     | ?- save_program(state, format('Restored!\n',[])).
     % /home/matsc/sicstus4/Bips/state.sav created in 0 msec
     yes
     
     | ?- restore(state).
     % restoring /home/matsc/sicstus4/Bips/state.sav...
     % /home/matsc/sicstus4/Bips/state.sav restored in 10 msec 16 bytes
     Restored!
     yes

See Also

restore/1, ref-sls, ref-sls-sst.


Send feedback on this subject.