Prolog Cafe User's Manual version 1.1
June 2008
Kobe University, JAPAN
Table of Contents
Install
Install for Unix, Linux, and Mac OS X
- Check if JavaTM1.5 or higher is installed.
> java -version
java version "1.5.0_13"
...
> javac -version
javac 1.5.0_13
...
- Unzip (or Untar) the distribution file, and then a directory named PrologCafeX.Y.Z will be created, where X.Y.Z is a version number.
> unzip PrologCafeX.Y.Z.zip
- Set the environment variable PLCAFEDIR.
> export PLCAFEDIR=~/PrologCafeX.Y.Z
> echo $PLCAFEDIR
/home/banbara/PrologCafeX.Y.Z
- Check if installation succeeds or not by launching a small Prolog interpreter.
> java -cp $PLCAFEDIR/plcafe.jar \
jp.ac.kobe_u.cs.prolog.lang.PrologMain \
jp.ac.kobe_u.cs.prolog.lang.builtin:cafeteria
...
| ?- halt.
bye
Install for Windows
Under construction.
Getting Started
Prolog Cafe is a Prolog-to-Java source-to-source translator system.
Prolog Cafe consists of three parts:
- Prolog-to-Java translator
Is written in Prolog. Source code is almost 3000 lines long, and its location is $PLCAFEDIR/src/compiler. This part is provided by the jp.ac.kobe_u.cs.prolog.compiler, jp.ac.kobe_u.cs.prolog.compiler.pl2am, and jp.ac.kobe_u.cs.prolog.compiler.am2j packages.
- Runtime system
Is written in Java. Source code is almost 5000 lines long, and its location is $PLCAFEDIR/src/lang. This part is provided by the jp.ac.kobe_u.cs.prolog.lang package.
- Built-in library
Most of built-in predicates are written in Prolog, and some of them are written in Java. Source code is almost 3000 lines long, and its location is $PLCAFEDIR/src/builtin. This part is provided by the jp.ac.kobe_u.cs.prolog.builtin package.
In this section, we explain how to use the Prolog Cafe interpreter
and translator by using N-Queens program as an example.
The goal of N-Queens is to place N queens on an N by N board such
that no piece attacks another.
queens.pl
main :-
queens(8, Qs), write(Qs), nl, fail.
queens(N,Qs) :-
range(1,N,Ns),
queens(Ns,[],Qs).
queens([],Qs,Qs).
queens(UnplacedQs,SafeQs,Qs) :-
select(UnplacedQs,UnplacedQs1,Q),
not_attack(SafeQs,Q),
queens(UnplacedQs1,[Q|SafeQs],Qs).
not_attack(Xs,X) :-
not_attack(Xs,X,1).
not_attack([],_,_) :- !.
not_attack([Y|Ys],X,N) :-
X =\= Y+N, X =\= Y-N,
N1 is N+1,
not_attack(Ys,X,N1).
select([X|Xs],Xs,X).
select([Y|Ys],[Y|Zs],X) :- select(Ys,Zs,X).
range(N,N,[N]) :- !.
range(M,N,[M|Ns]) :-
M < N,
M1 is M+1,
range(M1,N,Ns).
How to use the Prolog Cafe interpreter
Prolog Cafe provides a small Prolog interpreter.
The interpreter is useful for running and debugging Prolog
programs.
However, the execution speed is much slower than the translator
mentioned in Section 2.2[How to use the Prolog Cafe translator].
Preliminary
Save the program in List 2.1[queens.pl] as queens.pl.
Getting Started
To run the Prolog Cafe interpreter, perform the following command. The interpreter shows the prompt '| ?-' as soon as it is ready to accept inputs.
> java -cp $PLCAFEDIR/plcafe.jar \
jp.ac.kobe_u.cs.prolog.lang.PrologMain \
jp.ac.kobe_u.cs.prolog.builtin:cafeteria
...
| ?-
The plcafe.jar is the jar archive of Prolog Cafe runtime system and translator. The jp.ac.kobe_u.cs.prolog.lang.PrologMain is the main program. The jp.ac.kobe_u.cs.prolog.builtin:cafeteria is an argument to be passed to the main program, where the jp.ac.kobe_u.cs.prolog.builtin and cafeteria are the package name and predicate name of the interpreter.
Reading in Programs (consult)
Put a file in brackets and type it.
| ?- [queens].
{consulting /.../queens.pl ...}
{/.../queens.pl consulted, 170 msec}
| ?-
This instructs the interpreter to read in (consult) the program.
Executing Goals
Type a goal.
| ?- main.
[4,2,7,3,6,8,5,1]
[5,2,4,7,3,8,6,1]
[3,5,2,8,6,4,7,1]
...
no
| ?-
Debugging
Prolog Cafe provides a small debugger. The usage is almost same as other Prolog systems, and we omit it here. The following is a sample session of debugging.
| ?- spy(queens/3).
{Small debugger is switch on}
{spypoint user:queens/3 is added}
yes
{debug}
| ?- queens(4,X).
0 call : user:queens(4,_A2470C) ? l
+ 1 call : user:queens([1,2,3,4],[],_A2470C) ? l
+ 2 call : user:queens([2,3,4],[1],_A2470C) ? l
+ 3 call : user:queens([2,4],[3,1],_A2470C) ? l
+ 3 fail : user:queens([2,4],[3,1],_A2470C) ? l
+ 3 call : user:queens([2,3],[4,1],_A2470C) ? ?
Debuggin options:
a abort
RET creep
c creep
l leap
+ spy this
- nospy this
? help
h help
+ 3 call : user:queens([2,3],[4,1],_A2470C) ? -
{spypoint user:queens/3 is removed}
3 call : user:queens([2,3],[4,1],_A2470C) ? l
X = [3,1,4,2] ? ;
X = [2,4,1,3] ? ;
no
{debug}
| ?- nodebug.
{Small debugger is switch off}
yes
| ?-
Quit
Type halt. to exit from the interpreter.
| ?- halt.
bye
How to use the Prolog Cafe translator
Basic procedure to use the translator is as follows:
- Translate Prolog programs into Java programs.
- Compile translated code into Bytecode class files by using a Java compiler.
- Execute a goal in the interpreter or command line.
Preliminary
Save the program in List 2.1[queens.pl] as queens.pl.
Translating Prolog into Java
Create the work directory and move to there.
> ls
queens.pl
> mkdir work
> cd work/
Let us translate a Prolog file queens.pl into Java.
work> java -cp $PLCAFEDIR/plcafe.jar \
jp.ac.kobe_u.cs.prolog.compiler.Compiler ../queens.pl
...
work> ls
PRED_main_0.java PRED_not_attack_3.java PRED_queens_3.java PRED_select_3.java
PRED_not_attack_2.java PRED_queens_2.java PRED_range_3.java
The jp.ac.kobe_u.cs.prolog.compiler.Compiler is the class for translating Prolog into Java. The ../queens.pl is an input program to be passed to that class. After the translation succeeds, for each predicate in queens.pl, a file named PRED_f_n.java is created in the current directory, where f is the predicate name, and n is the arity.
Compiling Translated Code
Compile translated code by using the javac command.
work> javac -d . -cp $PLCAFEDIR/plcafe.jar *.java
Now, all of the predicates of queens.pl are compiled into Java bytecode in the current directory.
work> ls *.class
PRED_main_0.class PRED_not_attack_3_var_1.class PRED_range_3.class
PRED_not_attack_2.class PRED_queens_2.class PRED_range_3_1.class
PRED_not_attack_3.class PRED_queens_3.class PRED_range_3_2.class
PRED_not_attack_3_1.class PRED_queens_3_1.class PRED_range_3_sub_1.class
PRED_not_attack_3_2.class PRED_queens_3_2.class PRED_range_3_top.class
PRED_not_attack_3_top.class PRED_queens_3_var.class PRED_select_3.class
PRED_not_attack_3_var.class PRED_queens_3_var_1.class ................
Executing a Goal in the Interpreter
Add the current directory to the class path and execute goals on the interpreter.
work> java -cp .:$PLCAFEDIR/plcafe.jar \
jp.ac.kobe_u.cs.prolog.lang.PrologMain \
jp.ac.kobe_u.cs.prolog.builtin:cafeteria
...
| ?- main.
[4,2,7,3,6,8,5,1]
[5,2,4,7,3,8,6,1]
[3,5,2,8,6,4,7,1]
...
no
| ?- findall(X,queens(4,X),L).
L = [[3,1,4,2],[2,4,1,3]] ?
yes
Executing a Goal in the Commnad Line
By passing a top-level goal as atom to the PrologMain class, it is possible to execute it from command line without the interpreter.
work> java -cp .:$PLCAFEDIR/plcafe.jar \
jp.ac.kobe_u.cs.prolog.lang.PrologMain main
[4,2,7,3,6,8,5,1]
[5,2,4,7,3,8,6,1]
[3,5,2,8,6,4,7,1]
...
work>
Loading Predicates from Jar files
Create a jar file of class files.
work> jar cf ../queens.jar *.class
work> cd ..
> ls
queens.jar queens.pl work
Add that jar file to the class path and execute a goal.
> java -cp queens.jar:$PLCAFEDIR/plcafe.jar \
jp.ac.kobe_u.cs.prolog.lang.PrologMain main
[4,2,7,3,6,8,5,1]
[5,2,4,7,3,8,6,1]
[3,5,2,8,6,4,7,1]
...
Command Utilities
In this section,
we present basic tools, written in Perl, that are useful to develop
Prolog Cafe applications.
Table 3.1[Summary of Basic tools] shows the summary of them.
We use a list concatenation program in List 3.1[append.pl] as an example through this section.
append.pl
append([], Zs, Zs).
append([X|Xs], Ys, [X|Zs]) :- append(Xs, Ys, Zs).
Preliminary
Check if Perl 5 or higher is installed.
> perl -version
This is perl, v5.8.6 built for darwin-thread-multi-2level
(with 4 registered patches, see perl -V for more detail)
Copyright 1987-2004, Larry Wall
...
Set the environment variable PATH.
bash
> export PATH=$PLCAFEDIR/bin:$PATH
> echo $PATH
/home/banbara/PrologCafeX.Y.Z/bin:....
Check if the setup succeeds or not by launching a small Prolog interpreter.
> plcafe
...
| ?- halt.
bye
plcafe - Prolog Cafe application launcher
Usage
plcafe [options] [class] [argument...]
- options
- Command line options
- class
- Class name to be invoked
- argument
- Argument that is passed to the main function
Description
The plcafe command launches a Prolog Cafe application. If no argument is given, it launches a small interpreter.
> plcafe
...
| ?-
Options
- -h
- -help
- Print help message
- -v
- -verbose
- Enable verbose output
- -cp classpath
- -classpath classpath
- Set a list of directories, Jar archives, and Zip archives to search for class files. Class path entries (classpath) must be separated by colons (:).
> plcafe -cp $PLCAFEDIR/examples/prolog/maketen.jar
...
| ?- ex.
[1,1,5,8] 10=8/(1-1/5)
[1,1,9,9] 10=9*(1+1/9)
...
yes
| ?-
- -rt
- -runtime
- Boot the runtime system only, not including the compiler system.
- -t predicate_indicator
- -toplevel predicate_indicator
- Set a top-level goal to the main function of runtime system. The entry predicate_indicator is a goal name, or package and goal name separated by a colon (:). If this option is given, the arguments class and argument of plcafe command must be empty.
> plcafe -t ex -cp $PLCAFEDIR/examples/prolog/maketen.jar
...
[1,1,5,8] 10=8/(1-1/5)
[1,1,9,9] 10=9*(1+1/9)
...
>
- -J options
- Pass options to the java command. The entry options is an option list must be enclosed by single-quote (') .
> plcafe -J '-Xmx100m -verbose:gc' -t ex -cp \
$PLCAFEDIR/examples/prolog/maketen.jar
[GC 512K->215K(1984K), 0.0025620 secs]
[GC 724K->437K(1984K), 0.0015267 secs]
[GC 949K->469K(1984K), 0.0013030 secs]
...
[1,1,5,8] 10=8/(1-1/5)
...
[GC 1106K->599K(1984K), 0.0003398 secs]
[GC 1111K->594K(1984K), 0.0002695 secs]
[GC 1106K->594K(1984K), 0.0001862 secs]
...
[9,9,9,9] 10=(9+9*9)/9
>
pljava - Prolog to Java translator
Usage
pljava [options] [prolog_files]
- options
- Command line options
- prolog_files
- One or more prolog files to be translated
Description
The pljava command translates Prolog files into Java files.
Each predicate f/n, a java file named
PRED_f_n.java
will be created in the current directory.
For example, the following session translates the program of List 3.1[append.pl] into Java.
> ls
append.pl
> pljava append.pl
> ls
PRED_append_3.java append.pl
>
Options
- -h
- -help
- Print help message
- -v
- -verbose
- Enable verbose output
- -S
- Output WAM-like abstract machine code. For each of input prolog files, a file suffixed by ".am" will be created.
> ls
append.pl
> pljava -S append.pl
> ls
PRED_append_3.java append.am append.pl
>
- -d directory
- Set the destination directory for java files. The directory must already exist. The pljava does not create it.
> mkdir work
> ls
append.pl work
> pljava -d work append.pl
> ls -R
append.pl work
./work:
PRED_append_3.java
>
- -J options
- Pass options to the java command. The entry options is an option list must be enclosed by single-quote (') . For example, -J '-Xmx100m -verbose:gc'.
pljavac - Compile Prolog Cafe applications into Java bytecode
Usage
pljavac [options] [source_files]
- options
- Command line options
- source_files
- One or more source files to be compiled
Description
The pljavac command compiles Java programs
including Prolog Cafe API into Java bytecode class files.
For example, the following session compiles the program of List 3.1[append.pl] into Java bytecode class files
> ls
append.pl
> pljava append.pl
> pljavac *.java
> ls
PRED_append_3.class PRED_append_3_top.class
PRED_append_3.java PRED_append_3_var.class
PRED_append_3_1.class PRED_append_3_var_1.class
PRED_append_3_2.class append.pl
> plcafe -cp .
...
| ?- append([prolog], [java], X).
X = [prolog,java] ?
yes
| ?-
Options
- -h
- -help
- Print help message
- -v
- -verbose
- Enable verbose output
- -cp classpath
- -classpath classpath
- Set a list of directories, Jar archives, and Zip archives to search for class files. Class path entries (classpath) must be separated by colons (:).
- -C options
- Pass options to the javac command. The entry options is an option list must be enclosed by single-quote (') . For example, -C '-deprecation'.
plcomp - Prolog to Java bytecode compiler
Usage
plcomp [options] [prolog_files]
- options
- Command line options
- prolog_files
- One or more prolog files to be compiled
Description
The plcomp behaves as follows:
- translates Prolog files into Java files by invoking the pljava command.
- compiles those Java files into Java bytecode class files by invoking the pljavac command.
For example, the following session compiles the program of List 3.1[append.pl] into Java bytecode class files.
> ls
append.pl
> plcomp append.pl
> ls
PRED_append_3.class PRED_append_3_top.class
PRED_append_3.java PRED_append_3_var.class
PRED_append_3_1.class PRED_append_3_var_1.class
PRED_append_3_2.class append.pl
> plcafe -cp .
...
| ?- append([stag], [beetle], X).
X = [stag,beetle] ?
yes
| ?-
Options
- -h
- -help
- Print help message
- -v
- -verbose
- Enable verbose output
- -d directory
- Set the destination directory for java files and bytecode class files, and make it if no exist.
> ls
append.pl
> plcomp -d xxx append.pl
> ls -R
append.pl xxx
./xxx:
PRED_append_3.class PRED_append_3_top.class
PRED_append_3.java PRED_append_3_var.class
PRED_append_3_1.class PRED_append_3_var_1.class
PRED_append_3_2.class
>
- -J options
- Pass options to the java command. The entry options is an option list must be enclosed by single-quote (') . For example, -J '-Xmx100m -verbose:gc'.
- -cp classpath
- -classpath classpath
- Set a list of directories, Jar archives, and Zip archives to search for class files. Class path entries (classpath) must be separated by colons (:).
- -C options
- Pass options to the javac command. The entry options is an option list must be enclosed by single-quote (').
> ls
append.pl
> mkdir zzz
> plcomp -d xxx -C '-d zzz' append.pl
> ls -R
append.pl xxx zzz
./xxx:
PRED_append_3.java
./zzz:
PRED_append_3.class PRED_append_3_top.class
PRED_append_3_1.class PRED_append_3_var.class
PRED_append_3_2.class PRED_append_3_var_1.class
>
pljar - Create a Java archive (JAR) file of Prolog
Usage
pljar [options] [jar_file] [prolog_files]
- options
- Command line options
- jar_file
- Jar file to be created
- prolog_files
- One or more prolog files to be compiled
Description
The pljar command first translates Prolog files into Java
files, then compiles those Java files into bytecode class files, and
finally creates a JAR archive file of the class files.
The execution of 'pljar xxx.jar file.pl' behaves as follows:
- Makes two directories.
mkdir xxx xxx/classes
- Compiles file.pl into Java bytecode class files by invoking the plcomp command.
plcomp -C '-d xxx/classes' -d xxx file.pl
- Creates a JAR file xxx.jar by invoking the jar command.
jar cf xxx.jar -C xxx/classes .
For example, the following session creates a JAR file for the program of List 3.1[append.pl].
> ls
append.pl
> pljar append.jar append.pl
> ls -R
append append.jar append.pl
./append:
PRED_append_3.java classes
./append/classes:
PRED_append_3.class PRED_append_3_top.class
PRED_append_3_1.class PRED_append_3_var.class
PRED_append_3_2.class PRED_append_3_var_1.class
> plcafe -cp append.jar
...
| ?- append([prolog], [cafe], X).
X = [prolog,cafe] ?
yes
| ?-
Options
- -h
- -help
- Print help message
- -v
- -verbose
- Enable verbose output
- -J options
- Pass options to the java command. The entry options is an option list must be enclosed by single-quote (') . For example, -J '-Xmx100m -verbose:gc'.
- -cp classpath
- -classpath classpath
- Set a list of directories, Jar archives, and Zip archives to search for class files. Class path entries (classpath) must be separated by colons (:).
- -C options
- Pass options to the javac command. The entry options is an option list must be enclosed by single-quote (').
Built-in Predicates
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 4.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 4.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 4.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 4.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 4.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 4.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 4.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 |
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 ] |