- 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
- unload_file/1
- prolog_load_context/2
- source_location/2
- at_halt/1
- cancel_halt/1
- initialization/1
- initialization/2
- initialization/0
- compiling/0
- Conditional compilation and program transformation
- Reloading files, active code and threads
- Quick load files
- Loading Prolog source files
- Built-in Predicates
- Packages
- Reference manual
:- include(File).
appears. The include
construct is only honoured if it appears as a directive in a source
file. Textual include (similar to C/C++ #include) is obviously
useful for sharing declarations such as dynamic/1
or
multifile/1
by including a file with directives from multiple files that use these
predicates.
Textually including files that contain clauses is less obvious. Normally, in SWI-Prolog, clauses are owned by the file in which they are defined. This information is used to replace the old definition after the file has been modified and is reloaded by, e.g., make/0. As we understand it, include/1 is intended to include the same file multiple times. Including a file holding clauses multiple times into the same module is rather meaningless as it just duplicates the same clauses. Including a file holding clauses in multiple modules does not suffer from this problem, but leads to multiple equivalent copies of predicates. Using use_module/1 can achieve the same result while sharing the predicates.
If include/1 is used to load files holding clauses, and if these files are loaded only once, then these include/1 directives can be replaced by other predicates (such as consult/1). However, there are several cases where either include/1 has no alternative, or using any alternative also requires other changes. An example of the former is using include/1 to share directives. An example of the latter are cases where clauses of different predicates are distributed over multiple files: If these files are loaded with include/1, the directive discontiguous/1 is appropriate, whereas if they are consulted, one must use the directive multifile/1.
To accommodate included files holding clauses, SWI-Prolog distinguishes between the source location of a clause (in this case the included file) and the owner of a clause (the file that includes the file holding the clause). The source location is used by, e.g., edit/1, the graphical tracer, etc., while the owner is used to determine which clauses are removed if the file is modified. Relevant information is found with the following predicates:
- source_file/2 describes the owner relation.
- predicate_property/2 describes the source location (of the first clause).
- clause_property/2 provides access to both source and ownership.
- source_file_property/2 can be used to query include relationships between files.