4.3 Loading Prolog source files
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Loading Prolog source files
          • load_files/1
          • load_files/2
          • consult/1
          • ensure_loaded/1
          • include/1
          • require/1
          • encoding/1
          • make/0
          • library_directory/1
          • file_search_path/2
          • expand_file_search_path/2
          • prolog_file_type/2
          • source_file/1
          • source_file/2
          • source_file_property/2
          • exists_source/1
          • exists_source/2
          • unload_file/1
          • prolog_load_context/2
          • source_location/2
          • at_halt/1
          • cancel_halt/1
          • initialization/1
          • initialization/2
          • initialize/0
          • compiling/0
          • Conditional compilation and program transformation
          • Reloading files, active code and threads
          • Quick load files
    • Packages
Availability:built-in
Sourceinitialization(:Goal, +When)
Similar to initialization/1, but allows for specifying when Goal is executed while loading the program text:
now
Execute Goal immediately.
after_load
Execute Goal after loading the program text in which the directive appears. This is the same as initialization/1.
prepare_state
Execute Goal as part of qsave_program/2. This hook can be used for example to eagerly execute initialization that is normally done lazily on first usage.
restore_state
Do not execute Goal while loading the program, but only when restoring a saved state.58Used to be called restore. restore is still accepted for backward compatibility.
program
Execute Goal once after executing the -g goals at program startup. Registered goals are executed in the order encountered and a failure or exception causes the Prolog to exit with non-zero exit status. These goals are not executed if the -l is given to merely load files. In that case they may be executed explicitly using initialize/0. See also section 2.11.2.1.
main
When Prolog starts, the last goal registered using initialization(Goal, main) is executed as main goal. If Goal fails or raises an exception, the process terminates with non-zero exit code. If not explicitly specified using the -t the toplevel goal is set to halt/0, causing the process to exit with status 0. An explicitly specified toplevel is executed normally. This implies that -t prolog causes the application to start the normal interactive toplevel after completing Goal. See also the Prolog flag toplevel_goal and section 2.11.2.1.