Powered by SmartDoc

Built-in Predicates

June 2008
Mutsunori BANBARA and Naoyuki TAMURA
Kobe University, JAPAN

Table of Contents

We shall present the usage of builtin predicates with using mode. The mode of each argument indicates whether an argument shall be instantiated or not when the builtin predicate is executed. The mode is one of the following atoms.

Mode specification
+ The argument shall be instantiated.
? The argument shall be instantiated or a variable.
@ The argument shall remain unaltered.
- The argument shall be a variable that will be instantiated
if and only if the goal succeeds.
: The argument shall be instantiated to a term denoting a goal or a clause
that may or may not be prefixed by the package name.

Control constructs

true
otherwise
fail
false
!
?Term ^ :Callable_term
Goal1 , Goal2
Goal1 ; Goal2
Goal1 -> Goal2
call(:Callable_term)
catch(:Callable_term, ?Term1, :Term2)
throw(+Nonvar)
on_exception(?Term1, :Callable_term, :Term2)
raise_exception(+Nonvar)

Term unification

?Term1 = ?Term2
unify_with_occurs_check/2
Is not available yet.
?Term1 \= ?Term2

Type testing

var(@Term)
atom(@Term)
integer(@Term)
float(@Term)
atomic(@Term)
compound(@Term)
nonvar(@Term)
number(@Term)
java(@Term)
Checks that Term is currently instantiated to a java term.
| ?- java_constructor('java.lang.String'(hoge), X), java(X).
X = java.lang.String(3208229) ? 
yes
java(@Term1, ?Term2)
Checks that Term1 is currently instantiated to a java term. The result of the call is to unify Term2 with the full class name of underlying object of Term1.
| ?- current_input(X), java(X,Y).
X = java.io.PushbackReader(16632172),
Y = 'java.io.PushbackReader' ? 
yes
ground(@Term)
callable(@Term)

Term comparison

@Term1 == @Term2
@Term1 \== @Term2
@Term1 @< @Term2
@Term1 @> @Term2
@Term1 @=< @Term2
@Term1 @>= @Term2
?=(@Term1, @Term2)
compare(?Op_term, @Term1, @Term2)
sort(+List1, ?List2)
keysort(+List1, ?List2)

Term creation and decomposition

functor(-Nonvar, +Atomic, +Integer)
functor(+Nonvar, ?Atomic, ?Integer)
arg(+Integer, +Compound_term, ?Term)
+Nonvar =.. ?List
-Nonvar =.. +List
copy_term(?Term1, ?Term2)

Arithmetic evaluation

?Term is @Evaluable

Arithmetic comparison

@Evaluable1 =:= @Evaluable2
@Evaluable1 =\= @Evaluable2
@Evaluable1 < @Evaluable2
@Evaluable1 =< @Evaluable2
@Evaluable1 > @Evaluable2
@Evaluable1 >= @Evaluable2

Clause retrieval and information

clause(:Head, ?Callable_term)
current_predicate(?Predicate_indicator)
Is not available yet.

Clause creation and destruction

assert(:Clause)
assertz(:Clause)
asserta(:Clause)
retract(:Clause)
abolish(:Predicate_indicator)
retractall(:Head)

All solutions

findall(?Term, :Callable_term, ?List)
bagof(?Term, :Callable_term, ?List)
setof(?Term, :Callable_term, ?List)

Stream selection and control

current_input(?Stream)
current_output(?Stream)
set_input(@Stream_or_alias)
set_output(@Stream_or_alias)
open(@Source_sink, @IO_mode, -Stream)
open(@Source_sink, @IO_mode, -Stream, @Stream_options)
The stream-options type(T), reposition(Bool), and eof_action(Action) are not available yet.
close(@Stream_or_alias)
close(@Stream_or_alias, @Close_options)
The close-options are not available yet.
flush_output(@Stream_or_alias)
flush_output
stream_property(?Stream, ?Stream_property)
at_end_of_stream/0
Is not available yet.
at_end_of_stream/1
Is not available yet.
set_stream_position/2
Is not available yet.

Character input/output

get_char(?In_character)
get_char(@Stream_or_alias, ?In_character)
get_code(?In_character_code)
get_code(@Stream_or_alias, ?In_character_code)
peek_char(?In_character)
peek_char(@Stream_or_alias, ?In_character)
peek_code(?In_character_code)
peek_code(@Stream_or_alias, ?In_character_code)
put_char(+Character)
put_char(@Stream_or_alias, +Character)
put_code(+Character_code)
put_code(@Stream_or_alias, +Character_code)
nl
nl(@Stream_or_alias)
get0(?In_character_code)
get0(@Stream_or_alias, ?In_character_code)
get(?In_character_code)
get(@Stream_or_alias, ?In_character_code)
put(+Character_code)
put(@Stream_or_alias, +Character_code)
tab(+Evaluable)
tab(@Stream_or_alias, +Evaluable)
skip(+Evaluable)
skip(@Stream_or_alias, +Evaluable)

Byte input/output

get_byte/2
get_byte/1
peek_byte/2
peek_byte/1
put_byte/2
put_byte/1

Term input/output

read_term/3
Is not available yet.
read_term/2
Is not available yet.
read(?Term)
read(@Stream_or_alias, ?Term)
read_with_variables(?Term, ?List)
read_with_variables(@Stream_or_alias, ?Term, ?List)
read_line(?Character_code_list)
read_line(@Stream_or_alias, ?Character_code_list)
write(@Term)
write(@Stream_or_alias, @Term)
writeq(@Term)
writeq(@Stream_or_alias, @Term)
write_canonical(@Term)
write_canonical(@Stream_or_alias, @Term)
write_term(@Term, @Write_options_list)
write_term(@Stream_or_alias, @Term, @Write_options_list)
op(+Integer, +Op_specifier, @Atom_or_atom_list)
current_op(?Integer, ?Op_specifier, ?Atom)
char_conversion/2
Is not available yet.
current_char_conversion/2
Is not available yet.

Logic and control

\+(:Callable_term)
once(:Callable_term)
repeat

Atomic term processing

atom_length(+Atom, ?Integer)
atom_concat(?Atom, ?Atom, +Atom)
atom_concat(+Atom, +Atom, -Atom)
sub_atom(+Atom, ?Integer, ?Integer, ?Integer, ?Atom)
atom_chars(+Atom, ?Character_list)
atom_chars(-Atom, +Character_list)
atom_codes(+Atom, ?Character_code_list)
atom_codes(-Atom, +Character_code_list)
char_code(+Character, ?Character_code)
char_code(-Character, +Character_code)
number_chars(+Number, ?Character_list)
number_chars(-Number, +Character_list)
number_codes(+Number, ?Character_code_list)
number_codes(-Number, +Character_code_list)
name(+Atom_or_number, ?Character_code_list)
name(-Atom_or_number, +Character_code_list)

Implementation defined hooks

set_prolog_flag(+Flag, @Nonvar)
Some of flags are not available yet.
current_prolog_flag(?Flag, ?Term)
Some of flags are not available yet.
halt
halt(+Integer)
abort

DCG

'C'(?S1, ?Terminal, ?S2)
expand_term(@Term1, ?Term2)

Interoperating with Java

java_constructor(+Class(Arg1,...,Argn), ?Term)
Creates a new instance by calling the public constructor represented by Class(Arg1,...,Argn), and unifies the instance with Term. Class is a Java class name with full package path. Arg is an argument to be passed to the constructor call. Each of arguments is automatically converted to a corresponding Java object (See Table 1[Data conversion between Prolog and Java]). Place just an atom as Class instead if the constructor has no argument (n = 0).
| ?- java_constructor('java.awt.Frame', X).
X = java.awt.Frame(4160722) ? 
yes
| ?- java_constructor('java.lang.Integer'(100), X).
X = java.lang.Integer(100) ? 
yes
java_constructor0(+Class(Arg1,...,Argn), -Term)
Behaves the same as java_constructor/2 except that each of arguments (Argi) is NOT automatically converted.
java_declared_constructor(+Class(Arg1,...,Argn), ?Term)
Behaves the same as java_constructor/2 except that this creates a new instance by calling the public, protected, default (package) access, or private constructor.
java_declared_constructor0(+Class(Arg1,...,Argn), -Term)
Behaves the same as java_declared_constructor/2 except that each of arguments (Argi) is NOT automatically converted.
java_method(+Class_or_Instance, +Method(Arg1,...,Argn), ?Term)

Invokes the public member method (1) represented by Method(Arg1,...,Argn) of the class, interface, or instance represented by Class_or_Instance, and unifies a return object with Term. Method is a Java method name. Arg is an argument to be passed to the method call. Each of arguments is automatically converted to a corresponding Java object (See Table 1[Data conversion between Prolog and Java]). Place just an atom as Method instead if the method has no argument (n = 0). Method is a instance method if Class_or_Instance is a Java object. Method is a static method if Class_or_Instance is an atom representing a Java class name with full package path. The return object is automatically converted to a corresponding term by the inverse conversion of Table 1[Data conversion between Prolog and Java]. If the return type of Method is void, or the return object is null, Term remains unaltered.

| ?- java_method('java.lang.Math', abs(-1), X).
X = 1 ? 
yes

The following will display an empty frame on your desktop.

| ?- java_constructor('java.awt.Frame', X), 
     java_method(X, setSize(300,300), _), 
     java_method(X, show, _).

X = java.awt.Frame(14538812) ? 
yes
java_method0(+Class_or_Instance, +Method(Arg1,...,Argn), -Term)
Behaves the same as java_method/3 except that each of arguments (Argi) and the return object are NOT automatically converted.
java_declared_method(+Class_or_Instance, +Method(Arg1,...,Argn), ?Term)
Behaves the same as java_method/3 except that this invokes the public, protected, default (package) access, or private method, but not the inherited method.
java_declared_method0(+Class_or_Instance, +Method(Arg1,...,Argn), -Term)
Behaves the same as java_declared_method/3 except that each of arguments (Argi) and the return object are NOT automatically converted.
java_get_field(+Class_or_Instance, +Field, ?Term)

Gets the value of the public member field (2) represented by Field of the class, interface, or instance represented by Class_or_Instance, and unifies it with Term. Field is an atom that represents a Java field name. Field is a instance field if Class_or_Instance is a Java object. Field is a static field if Class_or_Instance is an atom representing a Java class name with full package path. The field object is automatically converted to a corresponding term by the inverse conversion of Table 1[Data conversion between Prolog and Java].

The following will display an empty frame on your desktop.

| ?- java_constructor('java.awt.Frame', X),
     java_method(X, setSize(300,300), _),
     java_get_field('java.lang.Boolean', 'TRUE', T),
     java_method(X, setVisible(T), _).

X = java.awt.Frame(4422554),
T = java.lang.Boolean(1231) ?
yes
java_get_field0(+Class_or_Instance, +Field, -Term)
Behaves the same as java_get_field/3 except that the field object is NOT automatically converted.
java_get_declared_field(+Class_or_Instance, +Field, ?Term)
Behaves the same as java_get_field/3 except that this gets the value of the public, protected, default (package) access, or private field, but not the inherited field.
java_get_declared_field0(+Class_or_Instance, +Field, -Term)
Behaves the same as java_get_declared_field/3 except that the field object is NOT automatically converted.
java_set_field(+Class_or_Instance, +Field, +Value)
Sets the value to the public member field (3) represented by Field of the class, interface, or instance represented by Class_or_Instance. Field is an atom that represents a Java field name. Value, a value to be set to the field, is automatically converted to a corresponding Java object (See Table 1[Data conversion between Prolog and Java]). Field is a instance field if Class_or_Instance is a Java object. Field is a static field if Class_or_Instance is an atom representing a Java class name with full package path.
java_set_field0(+Class_or_Instance, +Field, +Value)
Behaves the same as java_set_field/3 except that Value, a value to be set to the field, is NOT automatically converted.
java_set_declared_field(+Class_or_Instance, +Field, +Value)
Behaves the same as java_set_field/3 except that this sets the value to the public, protected, default (package) access, or private field, but not the inherited field.
java_set_declared_field0(+Class_or_Instance, +Field, +Value)
Behaves the same as java_set_declared_field/3 except that Value, a value to be set to the field, is NOT automatically converted.
synchronized(+Java_object, :Goal)
Behaves as call(:Goal) except that the underlying object of Java_object is locked during the execution of Goal.
java_conversion(+Term1, -Term2)
java_conversion(-Term1, +Term2)
Converts Term1 to a corresponding Java object according to Table 1[Data conversion between Prolog and Java] and unifies it with Term2 if Term2 is uninstantiated. Otherwise, converts the underlying Java object of Term2 to a corresponding term by the inverse conversion of Table 1[Data conversion between Prolog and Java].
| ?- java_conversion([1,2,[a,b]], Java), 
     java_conversion(Prolog, Java).
Java = java.util.Vector(34880),
Prolog = [1,2,[a,b]] ? 
yes
Data conversion between Prolog and Java
Prolog Java
integer java.lang.Integer
float java.lang.Double
atom java.lang.String
list java.util.Vector
Java_object Java Object
  1. The public member methods of the class or interface includes those declared by the class or interface and those inherited from superclasses and superinterfaces.
  2. The public member fields of the class or interface includes those declared by the class or interface and those inherited from superclasses and superinterfaces.
  3. (2)

Prolog interpreter

consult(@Files)
trace
notrace
debug
nodebug
leash(@Mode)
spy(:Predicate_indicator)
nospy(:Predicate_indicator)
nospyall
listing
listing(:Predicate_indicator)

Misc

length(?List, ?Integer)
numbervars(+Term, +Start, ?End)
statistics(+Key, ?Values)
Unifies system statistics determined by Key with Values. The possible keys and its values are as follows:
System statistics
key values
runtime [ since start , since previous statistics ]
trail [ used , free ]
choice [ used , free ]