Prolog directives are annotations inserted in Prolog source files for the compiler. A Prolog directive is used to specify:
Templates
Description
dynamic(Pred) specifies that the procedure whose predicate indicator is Pred is a dynamic procedure. This directive makes it possible to alter the definition of Pred by adding or removing clauses. For more information refer to the section about dynamic clause management (section 7.7.1).
This directive shall precede the definition of Pred in the source file.
If there is no clause for Pred in the source file, Pred exists however as an empty predicate (this means that current_predicate(Pred) succeeds).
In order to allow multiple definitions, Pred can also be a list of predicate indicators or a sequence of predicate indicators using ’,’/2 as separator.
Portability
ISO directive.
Templates
Description
public(Pred) specifies that the procedure whose predicate indicator is Pred is a public procedure. This directive makes it possible to inspect the clauses of Pred. For more information refer to the section about dynamic clause management (section 7.7.1).
This directive shall precede the definition of Pred in the source file. Since a dynamic procedure is also public. It is useless (but correct) to define a public directive for a predicate already declared as dynamic.
In order to allow multiple definitions, Pred can also be a list of predicate indicators or a sequence of predicate indicators using ’,’/2 as separator.
Portability
GNU Prolog directive. The ISO reference does not define any directive to declare a predicate public but it does distinguish public predicates. It is worth noting that in most Prolog systems the public/1 directive is as a visibility declaration. Indeed, declaring a predicate as public makes it visible from any predicate defined in any other file (otherwise the predicate is only visible from predicates defined in the same source file as itself). When a module system is incorporated in GNU Prolog a more general visibility declaration shall be provided conforming to the ISO reference.
Templates
Description
multifile(Pred) is not supported by GNU Prolog. When such a directive is encountered it is simply ignored. All clauses for a given predicate must reside in a single file.
Portability
ISO directive. Not supported.
Templates
Description
discontiguous(Pred) specifies that the procedure whose predicate indicator is Pred is a discontiguous procedure. Namely, the clauses defining Pred are not restricted to be consecutive but can appear anywhere in the source file.
This directive shall precede the definition of Pred in the source file.
In order to allow multiple definitions, Pred can also be a list of predicate indicators or a sequence of predicate indicators using ’,’/2 as separator.
Portability
ISO directive. The ISO reference document states that if there is no clause for Pred in the source file, Pred exists however as an empty predicate (i.e. current_predicate(Pred) will succeed). This is not the case for GNU Prolog.
Templates
Description
ensure_linked(Pred) specifies that the procedure whose predicate indicator is Pred must be included by the linker. This directive is useful when compiling to native code to force the linker to include the code of a given predicate. Indeed, if the gplc is invoked with an option to reduce the size of the executable (section 3.4.3), the linker only includes the code of predicates that are statically referenced. However, the linker cannot detect dynamically referenced predicates (used as data passed to a meta-call predicate). The use of this directive prevents it to exclude the code of such predicates.
In order to allow multiple definitions, Pred can also be a list of predicate indicators or a sequence of predicate indicators using ’,’/2 as separator.
Portability
GNU Prolog directive.
Templates
Description
built_in specifies that the procedures defined from now have the built_in property (section 7.8.2).
built_in(Pred) is similar to built_in/0 but only affects the procedure whose predicate indicator is Pred.
This directive shall precede the definition of Pred in the source file.
In order to allow multiple definitions, Pred can also be a list of predicate indicators or a sequence of predicate indicators using ’,’/2 as separator.
built_in_fd (resp. built_in_fd(Pred)) is similar to built_in (resp. built_in(Pred)) but sets the built_in_fd predicate property (section 7.8.2).
Portability
GNU Prolog directives.
Templates
Description
include(File) specifies that the content of the Prolog source File shall be inserted. The resulting Prolog text is identical to the Prolog text obtained by replacing the directive by the content of the Prolog source File.
See absolute_file_name/2 for information about the syntax of File (section 7.26.1).
Portability
ISO directive.
Templates
Description
ensure_loaded(File) is not supported by GNU Prolog. When such a directive is encountered it is simply ignored.
Portability
ISO directive. Not supported.
Templates
Description
op(Priority, OpSpecifier, Operator) alters the operator table. This directive is executed as soon as it is encountered by calling the built-in predicate op/3 (section 7.14.10). A system directive is also generated to reflect the effect of this directive at run-time (section 3.4.4).
Portability
ISO directive.
Templates
Description
char_conversion(InChar, OutChar) alters the character-conversion mapping. This directive is executed as soon as it is encountered by a call to the built-in predicate char_conversion/2 (section 7.14.12). A system directive is also generated to reflect the effect of this directive at run-time (section 3.4.4).
Portability
ISO directive.
Templates
Description
set_prolog_flag(Flag, Value) sets the value of the Prolog flag Flag to Value. This directive is executed as soon as it is encountered by a call to the built-in predicate set_prolog_flag/2 (section 7.22.1). A system directive is also generated to reflect the effect of this directive at run-time (section 3.4.4).
Portability
ISO directive.
Templates
Description
initialization(Goal) adds Goal to the set of goal which shall be executed at run-time. A user directive is generated to execute Goal at run-time. If several initialization directives appear in the same file they are executed in the order of appearance (section 3.4.4).
Portability
ISO directive.
Templates
Description
foreign(Template, Options) defines an interface predicate whose prototype is Template according to the options given by Options. Refer to the foreign code interface for more information (section 9.1).
foreign(Template) is equivalent to foreign(Template, []).
Portability
GNU Prolog directive.