Includes a file contents, which must be valid terms, at the place of occurrence of the directive. The file can be specified as a relative path, an absolute path, or using library notation and is expanded as a source file name. Relative paths are interpreted as relative to the path of the file containing the directive. The file extension is optional (the recognized Logtalk and Prolog file extensions are defined in the backend adapter files).

When using the reflection API, predicates from an included file can be distinguished from predicates from the main file by looking for the include/1 predicate declaration property or the include/1 predicate definition property. For the included predicates, the line_count/1 property stores the term line number in the included file.

This directive can be used as either a source file directive or an entity directive. As an entity directive, it can be used both in entities defined in source files and with the entity creation built-in predicates. In the latter case, the file should be specified using an absolute path or using library notation (which expands to a full path) to avoid a fragile dependency on the current working directory.

Included files may contain an encoding/1 directive, which may specify the same encoding of the main file or a different encoding.


When using this directive as an argument in calls to the create_object/4 and create_category/4 predicates, the objects and categories will not be recreated or redefined when the included file(s) are modified and the logtalk_make/0 predicate or the logtalk_make/1 (with target all) predicates are called.

Template and modes



% include the "raw_1.txt" text file found
% on the "data" library directory:
:- include(data('raw_1.txt')).

% include a "" file in the same directory
% of the source file containing the directive:
:- include('').

% include a file given its absolute path:
:- include('/home/me/databases/').

% create a wrapper object for a Prolog file using
% library notation to define the file path:
| ?- create_object(cities, [], [public(city/4), include(geo(''))], []).