The table below summarizes the built-in predicates available in PrologJ.
These fall into several categories, with some predicates belonging to more
than one category. The table indicates, for each builtin-predicate, what
categorie(s) it belongs to. An "X" indicates that a predicate is included in
a category. "EXT" indicates that an extended capability of the predicate is
included in that category, while the basic capabilities appear in another
category. The Grammar Rules category also includes special handling
for asserting clauses using -->/2 as a rule specifier, and
several categories include additional operators.
By default, all of the built-in predicates listed below are available. However,
when the PrologJ interpreter or compiler is started from the command line or
a script, the user can specify the category(s) of built-in predicates to use by
specifying the -l[ibrary] option on the command line. This option
is followed by one or more letters specifying the desired predicate category(s),
or by a hyphen (-) to use only the core predicates. If the
-l[ibrary] option is not used on the command line or script, or the
interpreter is started by running the file prologj.jar, all of the
built-in predicates are available.
If the interpreter is run with a console window, the set of available built-in predicates may also be examined or modified through the Library Components menu.
Built-in predicates in PrologJ fall into the following broad categories:
i" with
the -l[ibrary] option on the command line, or the "ISO" item in
the Library Components menu.
t" with
the -l[ibrary] option on the command line, or the "Traditional" item
in the Library Components menu.
c" with
the -l[ibrary] option on the command line, or the "Clause IO" item
in the Library Components menu.
d" with
the -l[ibrary] option on the command line, or the "Debugger" item
in the Library Components menu.
-->/2. The PrologJ implementation
of these operations is included in the "Grammar Rules" category, and
adheres to the discussion of the Prolog grammar rules facility in
[ Clocksin and Mellish 1994 ] chapter 9, to which he reader should refer for
documentation).
g" with
the -l[ibrary] option on the command line, or the "Grammar Rules" item
in the Library Components menu.
j" with
the -l[ibrary] option on the command line, or the "Java Interface" item
in the Library Components menu.
r" with
the -l[ibrary] option on the command line, or the "Relational
Interface" item in the Library Components menu.
setof/3 constructs a list whose
members are the various ways of satisfying a given goal. PrologJ adds
additional built-in predicates for performing operations on sets, such as set
union, intersection, and difference. These extensions are part of the "Set"
category, and are documented in conjunction with the discussion of the
extension that provides support for set operations.
s" with
the -l[ibrary] option on the command line, or the "Set" item
in the Library Components menu.
f" with
the -l[ibrary] option on the command line, or the "Fuzzy" item
in the Library Components menu.
m" with
the -l[ibrary] option on the command line, or the "Miscellaneous" item
in the Library Components menu.
In the table below, the column headed "Documentation" indicates where the reader can find documentation for the built-in predicate.
| Predicate | Documentation | core | ISO | TRA | TIO | CIO | DEB | GRA | JAV | REL | SET | FUZ | MIS |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
-l[ibrary] optionspecifier |
i |
t |
Bothi andt |
cor t |
d |
g |
j |
r |
s |
f |
m |
||
abolish/1 | DEC 1 | X | |||||||||||
abort/0 | html | X | |||||||||||
arg/3 | DEC 2 (CM 6.5) | X | |||||||||||
=:=/2 | DEC 3 (CM 6.12) | X | |||||||||||
=\=/2 | DEC 3 (CM 6.12) | X | |||||||||||
>/2 | DEC 3 (CM 6.12) | X | |||||||||||
>=/2 | DEC 3 (CM 6.12) | X | |||||||||||
</2 | DEC 3 (CM 6.12) | X | |||||||||||
=</2 | DEC 3 (CM 6.12) | X | |||||||||||
asserta/1 | DEC 4 (CM 6.4); html; html | X | EXT | EXT | |||||||||
assertz/1 | DEC 5 (CM 6.4); html; html | X | EXT | EXT | |||||||||
at_end_of_stream/0 | DEC 6 | X | |||||||||||
at_end_of_stream/1 | DEC 7 | X | |||||||||||
atom/1 | DEC 8 (CM 6.3) | X | |||||||||||
atom_chars/2 | DEC 9 | X | |||||||||||
atom_codes/2 | DEC 10 | X | |||||||||||
atom_concat/3 | DEC 11 | X | |||||||||||
atom_length/2 | DEC 12 | X | |||||||||||
atomic/1 | DEC 13 (CM 6.3) | X | |||||||||||
bagof/3 | DEC 14 | X | |||||||||||
biginteger/1 | html | X | |||||||||||
break/0 | html | X | |||||||||||
built_in/4 | html | X | |||||||||||
call/1 | DEC 15 (CM 6.7); html | X | EXT | ||||||||||
call_fuzzy/1 | html | X | |||||||||||
@/2 | html | X | |||||||||||
catch/3 | DEC 16; html | X | EXT | ||||||||||
char_code/2 | DEC 17 | X | |||||||||||
char_conversion/2 | DEC 18 | X | |||||||||||
clause/2 | DEC 19 (CM 6.4); html; html | X | EXT | EXT | |||||||||
close/1 | DEC 20; html | X | EXT | ||||||||||
close/2 | DEC 21 | X | |||||||||||
compound/1 | DEC 22 | X | |||||||||||
,/2 | DEC 23 (CM 6.7); html | X | EXT | ||||||||||
consult/1 | CM 6.1; html | X | X | ||||||||||
copy_term/2 | DEC 24 | X | |||||||||||
current_char_conversion/2 | DEC 25 | X | |||||||||||
current_input/1 | DEC 26 | X | |||||||||||
current_op/3 | DEC 27 | X | |||||||||||
current_output/1 | DEC 28 | X | |||||||||||
current_predicate/1 | DEC 29 | X | |||||||||||
current_prolog_flag/2 | DEC 30 | X | |||||||||||
!/0 | DEC 31 (CM 6.6) | X | |||||||||||
debugging/0 | CM 6.13; html | X | |||||||||||
deny/1 | html | X | |||||||||||
;/2 | DEC 32 (CM 6.7); html | X | EXT | ||||||||||
display/1 | CM 6.9; html | X | |||||||||||
display/2 | html | X | |||||||||||
fail/0 | DEC 33 (CM 6.2) | X | |||||||||||
filter_set/4 | html | X | |||||||||||
findall/3 | DEC 34 | X | |||||||||||
findset/3 | html | X | |||||||||||
float/1 | DEC 35 | X | |||||||||||
flush_output/0 | DEC 36 | X | |||||||||||
flush_output/1 | DEC 37 | X | |||||||||||
foreach/2 | html; html | EXT | X | ||||||||||
functor/3 | DEC 38 (CM 6.5) | X | |||||||||||
fuzzy_bagof/3 | html | X | |||||||||||
fuzzy_best/1 | html | X | |||||||||||
fuzzy_difference/3 | html | X | |||||||||||
fuzzy_findall/3 | html | X | |||||||||||
fuzzy_findset/3 | html | X | |||||||||||
fuzzy_intersection/3 | html | X | |||||||||||
fuzzy_setof/3 | html | X | |||||||||||
fuzzy_truth/1 | html | X | |||||||||||
fuzzy_union/3 | html | X | |||||||||||
get0/1 | CM 6.9; html | X | |||||||||||
get0/2 | html | X | |||||||||||
get/1 | CM 6.9; html | X | |||||||||||
get/2 | html | X | |||||||||||
get_byte/1 | DEC 39 | X | |||||||||||
get_byte/2 | DEC 40 | X | |||||||||||
get_char/1 | DEC 41 | X | |||||||||||
get_char/2 | DEC 42 | X | |||||||||||
get_code/1 | DEC 43 | X | |||||||||||
get_code/2 | DEC 44 | X | |||||||||||
halt/0 | DEC 45 | X | |||||||||||
halt/1 | DEC 46 | X | |||||||||||
->/2 | DEC 47; html | X | EXT | ||||||||||
-> ;/3 | DEC 48; html | X | EXT | ||||||||||
integer/1 | DEC 49 (CM 6.3) | X | |||||||||||
is/2 | DEC 50 (CM 6.11) | X | |||||||||||
listing/1 | CM 6.4; html; html | X | X | EXT | |||||||||
listing/2 | html; html | X | EXT | ||||||||||
name/2 | CM 6.5; see note 1 | X | |||||||||||
nl/0 | DEC 51 (CM 6.9) | X | |||||||||||
nl/1 | DEC 52 | X | |||||||||||
nodebug/0 | CM 6.13; html | X | |||||||||||
nonvar/1 | DEC 53 (CM 6.3) | X | |||||||||||
nospy/1 | CM 6.13; html | X | |||||||||||
not/1 | CM 6.7; html; see note 2 | X | EXT | ||||||||||
\+/1 | DEC 54; html | X | EXT | ||||||||||
notrace/0 | CM 6.13; html | X | |||||||||||
notrace/1 | html | X | |||||||||||
number/1 | DEC 55 | X | |||||||||||
number_chars/2 | DEC 56 | X | |||||||||||
number_codes/2 | DEC 57 | X | |||||||||||
object/1 | html | X | |||||||||||
once/1 | DEC 58; html | X | EXT | ||||||||||
op/3 | DEC 59 (CM 6.9) | X | |||||||||||
open/3 | DEC 60 | X | |||||||||||
open/4 | DEC 61; html; html | X | EXT | ||||||||||
peek_byte/1 | DEC 62 | X | |||||||||||
peek_byte/2 | DEC 63 | X | |||||||||||
peek_char/1 | DEC 64 | X | |||||||||||
peek_char/2 | DEC 65 | X | |||||||||||
peek_code/1 | DEC 66 | X | |||||||||||
peek_code/2 | DEC 67 | X | |||||||||||
phrase/2 | CM 9.3 | X | |||||||||||
put/1 | CM 6.9; html | X | |||||||||||
put/2 | html | X | |||||||||||
put_byte/1 | DEC 68 | X | |||||||||||
put_byte/2 | DEC 69 | X | |||||||||||
put_char/1 | DEC 70 | X | |||||||||||
put_char/2 | DEC 71 | X | |||||||||||
put_code/1 | DEC 72 | X | |||||||||||
put_code/2 | DEC 73 | X | |||||||||||
read/1 | DEC 74 (CM 6.9) | X | |||||||||||
read/2 | DEC 75 | X | |||||||||||
read_term/2 | DEC 76 | X | |||||||||||
read_term/3 | DEC 77 | X | |||||||||||
reconsult/1 | CM 6.1; html | X | X | ||||||||||
repeat/0 | DEC 78 (CM 6.6) | X | |||||||||||
retract/1 | DEC 79 (CM 6.4); html; html | X | EXT | EXT | |||||||||
retractall/1 | html; html html | EXT | EXT | X | |||||||||
see/1 | CM 6.10; html | X | |||||||||||
seeing/1 | CM 6.10; html | X | |||||||||||
seen/1 | CM 6.10; html | X | |||||||||||
set_difference/3 | html | X | |||||||||||
set_input/1 | DEC 80 | X | |||||||||||
set_intersection/3 | html | X | |||||||||||
set_output/1 | DEC 81 | X | |||||||||||
set_prolog_flag/2 | DEC 82 | X | |||||||||||
set_stream_position/2 | DEC 83 | X | |||||||||||
set_union/3 | html | X | |||||||||||
setof/3 | DEC 84 | X | |||||||||||
skip/1 | CM 6.9; html | X | |||||||||||
skip/2 | html | X | |||||||||||
spy/1 | CM 6.13; html | X | |||||||||||
stream_property/2 | DEC 85 | X | |||||||||||
sub_atom/5 | DEC 86 | X | |||||||||||
tab/1 | CM 6.9; html | X | |||||||||||
tab/2 | html | X | |||||||||||
tell/1 | CM 6.10; html | X | |||||||||||
telling/1 | CM 6.10; html | X | |||||||||||
@>/2 | DEC 87 | X | |||||||||||
@>=/2 | DEC 88 | X | |||||||||||
==/2 | DEC 89 (CM 6.8) | X | |||||||||||
@</2 | DEC 90 | X | |||||||||||
@=</2 | DEC 91 | X | |||||||||||
\==/2 | DEC 92 (CM 6.8) | X | |||||||||||
throw/1 | DEC 93 | X | |||||||||||
throw_error/1 | html | X | |||||||||||
told/0 | CM 6.10; html | X | |||||||||||
trace/0 | CM 6.13; html | X | |||||||||||
trace/1 | html | X | |||||||||||
true/0 | DEC 94 (CM 6.2) | X | |||||||||||
\=/2 | DEC 95 (CM 6.8) | X | |||||||||||
=/2 | DEC 96 (CM 6.8) | X | |||||||||||
unify_with_occurs_check/2 | DEC 97 | X | |||||||||||
=../2 | DEC 98 (CM 6.5) | X | |||||||||||
var/1 | DEC 99 (CM 6.3) | X | |||||||||||
write/1 | DEC 100 (CM 6.9) | X | |||||||||||
write/2 | DEC 101 | X | |||||||||||
write_canonical/1 | DEC 102 | X | |||||||||||
write_canonical/2 | DEC 103 | X | |||||||||||
write_error/1 | html | X | |||||||||||
write_error/2 | html | X | |||||||||||
write_term/2 | DEC 104; html | X | |||||||||||
write_term/3 | DEC 105; html | X | |||||||||||
writeq/1 | DEC 106 | X | |||||||||||
writeq/2 | DEC 107 | X |
Notes:
name/2 is implemented identically to atom_codes/2 and has the same error cases
not/1 is implemented identically to \+/1 and has the same error casesThe following built-ins have proven useful in the writing of Prolog code, and so are made available in PrologJ.
abortabort command in the debugger.biginteger(Term)Integer.MIN_VALUE or greater
than the Java constant Integer.MAX_VALUE.breakbreak/0 is used from within another break loop. This predicate
can be used to provide access to the interpreter from within compiled code
or the API. The newly-created interpreter loop is exited by entering
end-of-file. This predicate is equivalent to the break command
in the debugger.built_in(Functor, Arity, Type, Method)
Functor is an atomArity is a non-negative integerFunctor/Arity is the predicate indicator of a currently
accessible built-in predicate, then Type is unified with an
atom that indicates how this predicate is actually implemented in
PrologJ. This will be one of void, boolean,
redoable, or special.void indicates that the built-in is implemented by a
method of class Builtins that returns nothing because
the built-in predicate always succeeds.
boolean indicates that the built-in is implemented by a
method of class Builtins that returns true
if the built-in succeeds and false if it fails. (The
built-in can succeed at most once.)
redoable indicates that the built-in is one that can
succeed multiple times. It is implemented by a method that returns
a Choicepoint object if it succeeds; the
redo method of this object can be used to redo the
predicate. (If the initial call fails, the method returns
null.)
special indicates that both the interpreter and the
compiler contains special code for implementing this predicate.
Functor/Arity is the predicate indicator of a currently
accessible built-in predicate, and the predicate's type is other than
special, then Method is unified with
the name of the Java method used to implement this predicate in class
prologj.builtins.Builtins. (This parameter is ignored for
special predicates.)
| Conditions | Error Term |
|---|---|
Functor is a variable |
instantiation_error |
Functor is neither a variable nor an atom |
type_error(atom, Functor) |
Arity is a variable |
instantiation_error |
Arity is neither a variable nor an integer |
type_error(integer, Arity) |
Arity is an integer that is less than zero |
domain_error(not_less_than_zero, Arity) |
Arity is an integer that is greater than the maximum
arity for a compound term |
representation_error(max_arity) |
deny(Pred)Pred is a predicate indicator.Pred corresponds to an existing predicate written in
prolog, all existing clauses for the predicate
are removed from the database, but the predicate itself remains. This
is similar to abolish/1, except that only the clauses are
removed, not the predicate itself. Attributes specified by directives
such as :- dynamic/1 (or implicitly specified when the
predicate was created) remain.
abolish/1 is used on a predicate, and a goal is
subsequently called that uses that predicate, the behavior
of the system will depend on the setting of the unknown
flag. In the default case (flag setting error),
an error will result from the attempted call. If deny/1
is used on a predicate, and a goal is subsequently called that uses
that predicate, the goal will simply fail, regardless of the
setting of the unknown flag.
abolish/1, a
relational predicate with the same predicate indicator can be
created instead. If a prolog predicate is destroyed with
deny/1, an error will be thrown if an attempt is made
to create a relational predicate with the same predicate indicator.
Pred does not correspond to any existing predicate
in the database, then succeeds with empty local substitutions.
| Conditions | Error Term |
|---|---|
Pred is a variable, or Pred is
a term Name/Arity and either Name or
Arity is a variable |
instantiation_error |
Pred is neither a variable nor a term whose
principal functor is (/)/2 |
type_error(predicate_indicator, Pred) |
Pred is a term Name/Arity and
Name is neither a variable nor an atom. |
type_error(atom, Name) |
Pred is a term Name/Arity and
Arity is neither a variable nor an integer. |
type_error(integer, Arity) |
Pred is a term Name/Arity and
Arity is an integer less than zero. |
domain_error(not_less_than_zero, Arity) |
Pred is a term Name/Arity and
Arity is an integer greater than the maximum
permissible arity for a predicate. |
representation_error(max_arity) |
The predicate indicator Pred
is that of a static procedure, and the flag
enforce_directives is on |
permission_error(modify, static_procedure, Pred)
|
The predicate indicator Pred
is that of a built-in procedure |
permission_error(modify, static_procedure, Pred)
|
The predicate indicator Pred
is that of a relational-database procedure |
permission_error(modify, defined_procedure, Pred)
|
foreach(Goal1, Goal2)Goal1 is a callable goalGoal2 is a callable goal. Typically, it has one or more
variables in common with Goal1.Goal1 is called as if by call/1. For each
way that Goal1 succeeds, Goal2 is called as
if by once/1. The overall goal succeeds just if
Goal2 succeeds for each way Goal1 succeeds.
If Goal2 ever fails, further possibilities for
Goal1 are not tried, and the overall goal fails at once.
(If Goal1 never succeeds, then the overall goal succeeds
vacuously.) Any uninstantiated variables occurring in the arguments
are uninstantiated when the predicate succeeds.foreach/2 is true if the
predicate represented by its second goal is satisfied for every
way of satisfying the predicate represented by its first goal.
| Conditions | Error Term |
|---|---|
Goal1 is a variable |
instantiation_error |
Goal1 is neither a variable nor a callable
term |
type_error(callable, Goal1) |
Goal2 is a variable |
instantiation_error |
Goal2 is neither a variable nor a callable
term |
type_error(callable, Goal2) |
retractall(Clause)Clause is either a callable term, or term of the
form Head :- Body. (In the former case,
Head is Clause and Body
is an uninstantiated variable.)Head and whose body unifies with Body are
retracted. This predicate succeeds exactly once, even if
there are no matching clauses. Any uninstantiated variables occurring
in the argument remain uninstantiated when the predicate succeeds.
retractall/1 behaves as if it were defined as follows,
though in fact it is implemented directly and hence more efficiently
(especially when used with a relational database table predicate). Cf
[ Clocksin and Mellish 1994 ] section 7.13.
retractall(X) :- retract(X), fail.
retractall(X) :- retract(X :- Y), fail.
retractall(_).
| Conditions | Error Term |
|---|---|
Clause is a variable |
instantiation_error |
Clause is neither a variable nor a callable
term |
type_error(callable, Clause) |
The predicate indicator PI of Clause
is that of a static procedure, and the flag
enforce_directives is on |
permission_error(modify, static_procedure, PI)
|
The predicate indicator PI of Clause
is that of a built-in procedure |
permission_error(modify, static_procedure, PI)
|
throw_error(Error)Error is an error term.prologj.throwable.PrologError) and throws it.Error argument is not valid, one
of the following is thrown instead of the error specified by
the argument. | Conditions | Error Term |
|---|---|
Error is a variable |
instantiation_error |
Error is neither a variable nor an atom nor a
compound term |
type_error(compound, Error) |
Error is a compound term, one of whose arguments
is a variable |
instantiation_error |
Error is a compound term, one of whose arguments
A (except the very last) is neither a variable nor an
atom. (Note: the last argument can be any non-variable term, since
it represents the term giving rise to the error) |
type_error(atom, A) |
write_error(ErrorObject)ErrorObject is an actual error object (instance of
prologj.throwable.PrologError) that was thrown as
by throw_error/1 or by the PrologJ system. It will be
the second argument of a ball of the form error/2 that was
caught by catch/3 in such cases.| Conditions | Error Term |
|---|---|
ErrorObject is a variable |
instantiation_error |
ErrorObject is neither a variable nor an
instance of prologj.throwable.PrologError |
system_error(not_prolog_error, ErrorObject) |
write_error(ErrorObject, Stream_or_alias)
ErrorObject is an actual error object (instance of
prologj.throwable.PrologError) that was thrown as
by throw_error/1 or by the PrologJ system. It will be
the second argument of a ball of the form error/2 that was
caught by catch/3 in such cases.Stream_or_alias is a stream term or an alias for a stream
representing the stream - generally an input stream - on which the error
occurred. (Note: this is generally not the same as the stream
to which the message will be written!) Information about this stream
and the current location in it will be included in the error printout -
similar to the information printed by the interpreter when an error
occurs during an operation such as consult/1.| Conditions | Error Term |
|---|---|
ErrorObject is a variable |
instantiation_error |
ErrorObject is neither a variable nor an
instance of prologj.throwable.PrologError |
system_error(not_prolog_error, ErrorObject) |
Stream_or_alias is a variable |
instantiation_error |
Stream_or_alias is a neither variable, nor a stream term,
or alias. |
domain_error(stream_or_alias, Stream_or_alias)
|
Stream_or_alias is not associated with an
open stream. |
existence_error(stream, Stream_or_alias) |