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 8.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 8.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) specifies that the procedure whose predicate indicator is Pred is a multifle procedure (the clauses of Pred can reside in several source files). This directive is only supported by GNU Prolog since version 1.4.0.
The native compilation scheme of GNU Prolog requires that each Prolog source file refering to a multifile predicate Pred must include a multifile(Pred) directive even if no clause are defined in this file for Pred (i.e. Pred is only called by other predicates in this source file).
Portability
ISO directive.
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.
A multifile predicate (declared with a multifile/1 directive) cannot be directly called from a file where it is not declared as multifile (the native compiler must know the called predicate is multifile). Workarounds: either call it via a meta-call (e.g. using call/1) or declare it as multifile in the calling source file). A good habit is to encapsulate a multifile predicate in a monofile predicate which invokes it (external call only invoke the monofile wrapper predicate).
Portability
ISO directive.
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 4.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 8.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 8.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.
In case of File is a relative file name, it is searched in the current directory. If it is not found it is then searched in each directory of parent includers.
See absolute_file_name/2 for information about the syntax of File (section 8.26.1).
Portability
ISO directive.
Templates
Description
These directives are for conditional compilation.
if(Goal) compile subsequent code only if Goal succeeds. Goal is first processed by expand_term/2 (section 8.17.2). If Goal raises an exception it is printed and Goal fails.
else introduces the else part.
endif terminates a conditional compilation part.
elif(Goal) is a shorthand for :- else. :- if(Goal). … :- endif.
Portability
GNU Prolog directive. Also in SWI and YAP.
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 8.14.10). A system directive is also generated to reflect the effect of this directive at run-time (section 4.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 8.14.12). A system directive is also generated to reflect the effect of this directive at run-time (section 4.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 8.22.1). A system directive is also generated to reflect the effect of this directive at run-time (section 4.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 4.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 10.3).
foreign(Template) is equivalent to foreign(Template, []).
Portability
GNU Prolog directive.