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. | |
| ?- java_constructor('java.lang.String'(hoge), X), java(X).
X = java.lang.String(3208229) ?
yes
| ?- current_input(X), java(X,Y). X = java.io.PushbackReader(16632172), Y = 'java.io.PushbackReader' ? yes
| ?- 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
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
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_conversion([1,2,[a,b]], Java),
java_conversion(Prolog, Java).
Java = java.util.Vector(34880),
Prolog = [1,2,[a,b]] ?
yes
| Prolog | Java |
|---|---|
| integer | java.lang.Integer |
| float | java.lang.Double |
| atom | java.lang.String |
| list | java.util.Vector |
| Java_object | Java Object |
| key | values |
|---|---|
| runtime | [ since start , since previous statistics ] |
| trail | [ used , free ] |
| choice | [ used , free ] |