Fine Tuning

To tune the initialization of a file or system to be run only when it should be run, volatile/1, in combination with other declarations, give initialization/1 the information necessary to distinguish different loading situations. In the reference pages, we show how some common situations can be programmed using these predicates.

If a source file contains data that is supposed to be transformed according to some complicated rules (which cannot be done with term_expansion/2), and the data after the transformation can be saved into a saved state, we might want the transformation to be done when the file is loaded, but not when a saved state is restored. The following program defines the initialization to be run only when the file is loaded:

     :- dynamic do_not_transform/0. % reset fact
     :- initialization my_init.
     
     my_init :-
       ( do_not_transform ->
         true
       ; undo_transform, % remove old data
         do_transform,
         assert(do_not_transform)
       ).
     

In the above example, do_transform/0 and undo_transform/0 are user defined.