PrologJ recognizes 13 directives of the form :-/1. Any can appear
in a source file that is being read by the compiler. Most can appear in
a file that is being consulted by using the Prolog built-in predicates
consult/1 or reconsult/1 or by the using the API
methods consult() or reconsult(). Many can also
appear in input to the interpreter. Insofar as possible, these directives
produce equivalent results, regardless of how they are read. The following
table shows the contexts in which the various directives may appear.
| Directive | Permitted Contexts |
|---|---|
:- char_conversion | Compiler source or consulted source only. (Notes 1, 2) |
:- comment | Compiler source or consulted source only. (Note 5) |
:- discontiguous | Any |
:- dynamic | Any |
:- ensure_loaded | Any |
:- entry | Compiler source only (Note 4) |
:- include | Compiler source or consulted source only. (Note 3) |
:- initialization | Compiler source or consulted source only. (Note 3) |
:- main | Compiler source only (Note 4) |
:- multifile | Any |
:- op | Compiler source or consulted source only. (Notes 1, 2) |
:- package | Compiler source only (Note 4) |
:- dynamic | Any |
:- set_prolog_flag | Compiler source or consulted source only. (Notes 1, 2) |
Notes:
char_conversion/2, op/3
or set_prolog_flag/2 built-in should be called in an
:- initialization/1 directive as well. (Both are needed;
the directive to affect the reading of the file, and the built-in predicate
call to affect the execution of the program contained in the file.)
char_conversion/2, op/3 or
set_prolog_flag/2 can be used as interpreted goals with
the same effect.char_conversion(In_char, Out_char)char_conversion/2. See discussion above
for the duration of the effect of this directive.
comment(Text)Text is an atom (typically, though not necessarily,
a string enclosed in single quotes ('). It is an error
for it to be of any other type.discontiguous(Predicate)Predicate is either a predicate indicator (term
of the form Functor/Arity) or a list of predicate
indicators or a predicate indicator sequence (series of predicate
indicators separated by commas).
dynamic(Predicate)Predicate is either a predicate indicator (term
of the form Functor/Arity) or a list of predicate
indicators or a predicate indicator sequence (series of predicate
indicators separated by commas).
ensure_loaded(Name)Name is the base name of a file of Prolog code which
must also be loaded when this file is executed. (If the file in
which it occurs is being compiled, that is at run time, not
compile time.)
:- package/1
directive), then the name appearing here must include the package
specification as well. .pro
extension need not be specified. The name specified may be either
a relative or absolute pathname in accordance with the requirements
of the underlying platform. A relative path is treated as relative
to the path of the file containing this directive.
ensure_loaded flag at the time the directive is read
(compile time if the file containing it is being compiled.)compiled or
the flag value is default and the directive appears in a
file that is being compiled.source.
either, or it is default
and the directive appears in a file that is being read as a source file,
then the system first searches for a suitable compiled file and then
for a source file if a compiled version cannot be found. In this case,
the Name parameter cannot contain both a package specification
and a path specification. If it contains a ., the system
assumes that a package specification is present, and uses
this specification when searching for a compiled file, but strips it
off (and appends a .pro extension) when searching for a
source file. For this reason, the Name parameter should
never contain an explicit .pro extension if
either kind of file can be sought, since that would cause the base
name of the file to be interpreted as a package specication for
a file whose base name is pro.
entry(Signature)Signature is either an atom whose name is a legitimate Java
method name, or a compound term whose functor is such a name. If
it is a compound term, each of its arguments must be one of the
following:booleanintdouble'String''Object'public static boolean method having
the functor of Signature as its name, and parameters as
specified by the arguments of Signature (no parameters if
Signature is an atom). The method will call a Prolog
goal (as if by once/1) whose functor is the same as the name
of the method, whose arity is the same as the arity of
Signature, and whose arguments are converted, respectively,
totrue or failPrologException.
include(Name)Name the base name of a file of Prolog code to be included.
The extension .pro is automatically appended; however,
it is not an error to explicitly specify it, in which case a second
copy is not appended. (E.g. :- include(foo) and
:- include('foo.pro') are equivalent.)
Name parameter may be either a relative or absolute pathname
in accordance with the requirements of the underlying platform. A relative
path is treated as relative to the path of the file containing this directive.
initialization(Goal)Goal a valid Prolog goal.
:- ensure_loaded directives - has/have
been read. If this directive occurs in code being read by the compiler,
the generated code will execute the specified goal after it - and any
other code specified by :- ensure_loaded directives - has/have
been loaded.
main(Name)Name the name of a predicate of arity 1 that has already
been defined in this source file. It is an error to specify a predicate
that has not yet been defined.
main/1 directive can occur only once in the file(s) comprising
an application. The argument is taken as the name of a predicate of arity
1 that is to be called as the main goal of the compiled application after
all files comprising the application have been loaded. The single
argument of this predicate will be a list corresponding to the
String [] args parameter of a Java main
method, with one element for each member of this array (an empty list
([]) if no command-line arguments are specified).
main() method written
in Java, then it should not contain a :- main directive)
multifile(Predicate)Predicate is either a predicate indicator (term
of the form Functor/Arity) or a list of predicate
indicators or a predicate indicator sequence (series of predicate
indicators separated by commas).
op(Priority, Op_specifier, Operator)op/3. See discussion
above for the duration of the effect of this directive.
package(Name)Name is a valid Java package name (which may include
.).
package statement at the start of the generated Java.
Because Java requires this statement to preceed any other statement in
the file, a :- package directive, if it occurs, must occur
before any other directive or clause in the Prolog source file.
public(Predicate)Predicate is either a predicate indicator (term
of the form Functor/Arity) or a list of predicate
indicators or a predicate indicator sequence (series of predicate
indicators separated by commas).
set_prolog_flag(Flag, Value)set_prolog_flag/2. See discussion above
for the duration of the effect of this directive.
Notes:
enforce_directives
flag is off, information about the properties of predicates
is still maintained, but these requirements are not enforced.asserta/1, assertz/1, retract/1
or retractall/1. Only public predicates can be accessed
by clause/2. (A predicate that is made dynamic is also
automatically made public.) Predicates created by asserta/1
or assertz/1 are made dynamic and public, but predicates
created by clauses in a source file are static and private unless
explicitly declared otherwise.enforce_directives
flag is off, information about the properties of predicates
is still maintained, but these requirements are not enforced.