Directives

The following directives may occur in Prolog source files being read by consult/1 or reconsult/1 or by the compiler; some may also be entered interactively.
 

char_conversion
Prototype: :- char_conversion(InChar, OutChar)
Same as the builtin predicate
char_conversion/2 but only applies to the file in which it occurs and any files included by it.
Only allowed in source files read by consult/1 or reconsult/1, or by the compiler.
Example: :- char_conversion(a, b) - causes every occurrence of a in unquoted input in the current file to be replaced by b.
 
op
Prototype: :- op(Priority, Associativity, Symbol)
Same as the builtin predicate
op/3 but only applies to the file in which it occurs and any files included by it.
Only allowed in source files read by consult/1 or reconsult/1, or by the compiler.
Example: :- op(1000, xfy, foo) - makes foo an infix operator with priority 1000 and left associativity for the remainder of the current file.
 
set_prolog_flag
Prototype: :- set_prolog_flag(Name, Value)
Same as the builtin predicate
set_prolog_flag/2 but only applies to the file in which it occurs and any files included by it.
Only allowed in source files read by consult/1 or reconsult/1, or by the compiler.
Example: :- set_prolog_flag(enforce_directives, off) - set the enforce_directives flag to off for the remainder of the current file.
 
discontiguous
Prototype: :- discontiguous(PredicateIndicatorListOrSequence)
Declares one or more predicates to be discontiguous. Normally, all clauses for a given functor/arity in a source file must occur one after another, with no intervening clauses for another functor/arity; this is not required for a discontiguous predicate. However, this requirement is not enforced if the enforce_directives flag is off.
Allowed in all contexts.
Example: :- discontiguous(test/1) - declares test/1 discontiguous.
Example: :- discontiguous([ test/1, test/2 ]) - declares test/1 and test/2 to be discontiguous.
Example: :- discontiguous(test/1, test/2) - declares test/1 and test/2 to be discontiguous.
 
dynamic
Prototype: :- dynamic(PredicateIndicatorListOrSequence)
Declares one or more predicates to be dynamic. Clauses for a dynamic predicate may be added by asserta/1 or assertz/1 or removed by deny/1, retract/1, or retractall/1. However, this requirement is not enforced if the enforce_directives flag is off.
Allowed in all contexts, but must preceed any clauses for the predicate.
Example: :- dynamic(test/1) - declares test/1 dynamic.
Example: :- dynamic([ test/1, test/2 ]) - declares test/1 and test/2 to be dynamic.
Example: :- dynamic(test/1, test/2) - declares test/1 and test/2 to be dynamic.
 
local
Prototype: :- local(PredicateIndicatorListOrSequence)
Declares one or more predicates to be local. In compiled code, a local predicate is only visible to other clauses defined in the same source file.
Allowed in all contexts, but only meaningful in source code being compiled, and must preceed any clauses for the predicate.
Example: :- local(test/1) - declares test/1 local.
Example: :- local([ test/1, test/2 ]) - declares test/1 and test/2 to be local.
Example: :- local(test/1, test/2) - declares test/1 and test/2 to be local.
 
multifile
Prototype: :- multifile(PredicateIndicatorListOrSequence)
Declares one or more predicates to be multifile. Normally, all clauses for a given functor/arity must occur in a single source file, but this is not required for multifile predicates. However, this requirement is not enforced if the enforce_directives flag is off.
Allowed in all contexts, but must preceed any clauses for the predicate.
Example: :- multifile(test/1) - declares test/1 multifile.
Example: :- multifile([ test/1, test/2 ]) - declares test/1 and test/2 to be multifile.
Example: :- multifile(test/1, test/2) - declares test/1 and test/2 to be multifle.
 
public
Prototype: :- public(PredicateIndicatorListOrSequence)
Declares one or more predicates to be public. Clauses for a public predicate may be accessed by clause/2. (If a predicate is declared to be dynamic, it is automatically made public as well.)However, this requirement is not enforced if the enforce_directives flag is off.
Allowed in all contexts, but must preceed any clauses for the predicate.
Example: :- public(test/1) - declares test/1 public.
Example: :- public([ test/1, test/2 ]) - declares test/1 and test/2 to be public.
Example: :- public(test/1, test/2) - declares test/1 and test/2 to be public.
 
ensure_loaded
Prototype: :- ensure_loaded(Module)
Ensures that a module named Module is loaded. The compiled form of a module is always loaded when this directive appears in source code being compiled. In other contexts, whether a compiled or source file is loaded depends on the setting of the
ensure_loaded flag.
Allowed in all contexts. If this directive appears in source code for the compiler, it is not executed until the compiled code is loaded; in other contexts, it is executed immediately.
 
entry
Prototype: :- entry(Signature, PrologName)
Declares an entry point in Prolog code that can be called from Java - see the
documentation for the Java extension.
Meaningful only in source code being compiled, but also allowed (though ignored) in source files read by consult/1 or reconsult/1
Example: :- entry(test(int), test) - declares a Java entry whose signature is test(int) that calls the Prolog predicate test/1.
 
function
Prototype: :- function(Indicator, ClassName)
Declares an arithmetic function written in Java that can be called from Prolog code. Indicator specifies the Prolog name for the function, and whether it is binary, unary, or zeroary. The specified class implements the function - it must implement one of the interfaces PrologBinaryFunction, PrologUnaryFunction, or PrologZeroaryFunction, as appropriate.
Allowed in all contexts
Example: :- function(f/1, MyFunction) - declares a unary function named f that is implemented by the Java class MyFunction, which must implement PrologUnaryFunction.
 
include
Prototype: :- include(Path)
Causes the file specified by Path to be included into the file being read at the point where the directive occurs.
Only allowed in source files read by consult/1 or reconsult/1, or by the compiler.
Example: :- include('foo/bar') - causes foo/bar.pro to be included into the source file.
 
initialization
Prototype: :- initialization(Goal)
Specifies an initialization goal to be called when the file this directive occurs in is consulted, or when the code generated by compiling it is loaded.
Only allowed in source files read by consult/1 or reconsult/1, or by the compiler.
Example: :- initialization(test(3)) - the goal test(3) will be called when the file in which this directive occurs is consulted, or when code generated by compiling it is loaded.
 
java
Prototype: :- java(Indicator, Type, ClassName, Signature, ValueSpecifier)
Declares a Prolog predicate that invokes a Java method or accesses a field of a Java object or class. See the
documentation for the Java extension.
Allowed in all contexts.
Example: :- java(example/1, method, MyClass, someMethod(int), _) - declares example/1 as a Java predicate invoking the class method someMethod of class MyClass, with a single integer parameters.
 
main
Prototype: :- main(Functor)
Declares a Prolog predicate that will serve as the main program for an application written in Prolog. See the
documentation for the Java extension.
Meaningful only in source code being compiled, but also allowed (though ignored) in source files read by consult/1 or reconsult/1
Example: :- main(main) - when this program is run, the goal main/1 (with arguments the command line arguments) will be the starting point for execution.
 
message
Prototype: :- message(Message, CompilerOnly)
Writes Message to current output when this directive is read while reading the file in which it occurs.
Only allowed in source files read by consult/1 or reconsult/1, or by the compiler. If CompilerOnly is true, the message is only printed when reading this file during compilation.
 
sql
Prototype: :- sql(Indicator, Type, URL, TableNameOrQuery)
Declares a Prolog predicate that invokes a relational database. operation. See the
documentation for the Relational extension.
Allowed in all contexts.
Example: :- sql(example/3, table, 'jdbc:mysql://localhost/mydatabase', sometable) - declares example/3 as a relational database predicate accessing the table sometable in the mysql database mydatabase on the local computer.