Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

convert prolog source code to Java

793 views
Skip to first unread message

Henrique Seganfredo

unread,
Oct 10, 2002, 9:32:14 AM10/10/02
to
Hi folks, where can I find a prolog converter to Java? I have a simple
program here that I would like to see its size and complexity in Java...

Thanks,

--
Henrique Seganfredo (Segao)

henrique at seganfredo dot com
ICQ 340812

computer geek

Fergus Henderson

unread,
Oct 10, 2002, 11:24:00 AM10/10/02
to
"Henrique Seganfredo" <henr...@seganfredo.com> writes:

>Hi folks, where can I find a prolog converter to Java? I have a simple
>program here that I would like to see its size and complexity in Java...

If you want to generate readable, maintainable Java code,
it's a difficult task.

The Mercury compiler has some experimental support for compiling
Mercury to Java. As far as I know this is the only implementation
which really translates logic programming code to Java, rather than
e.g. translating to WAM and writing a WAM interpreter in Java.
However, I really haven't been keeping track of the competition in
this area recently.

Shown below is an example Mercury module (which solves the 8-queens
problem), together with the Java code that the Mercury compiler outputs.
I have deleted some unused functions from the generated code.
As you can see, there are still some obvious ways in which the
generated code could be simplified, e.g. avoiding unnecessary
temporary variables.

To build and run this, I did `cd java; mmake' in the Mercury distribution's
source directory, set my CLASSPATH to point to that `java' directory,
ran `mmc --target java queens.m', deleted a few unused functions from the
generated `.java' file, ran `javac queens.java' and then `java queens'.

%-----------------------------------------------------------------------------%
MERCURY SOURCE CODE
%-----------------------------------------------------------------------------%
:- module queens.
:- interface.
:- import_module io.

:- pred main(io__state, io__state).
:- mode main(di, uo) is cc_multi.

:- implementation.
:- import_module int.

:- type list(T) ---> [] ; [T|list(T)].

main -->
( { data(Data), queen(Data, Out) } ->
print_list(Out)
;
io__write_string("No solution\n")
).

:- pred data(list(int)).
:- mode data(out) is det.

data([1,2,3,4,5,6,7,8]).

:- pred queen(list(int), list(int)).
:- mode queen(in, out) is nondet.

queen(Data, Out) :-
qperm(Data, Out),
safe(Out).

:- pred qperm(list(int), list(int)).
:- mode qperm(in, out) is nondet.

qperm([], []).
qperm([X|Y], K) :-
qdelete(U, [X|Y], Z),
K = [U|V],
qperm(Z, V).

:- pred qdelete(int, list(int), list(int)).
:- mode qdelete(out, in, out) is nondet.

qdelete(A, [A|L], L).
qdelete(X, [A|Z], [A|R]) :-
qdelete(X, Z, R).

:- pred safe(list(int)).
:- mode safe(in) is semidet.

safe([]).
safe([N|L]) :-
nodiag(N, 1, L),
safe(L).

:- pred nodiag(int, int, list(int)).
:- mode nodiag(in, in, in) is semidet.

nodiag(_, _, []).
nodiag(B, D, [N|L]) :-
NmB is N - B,
BmN is B - N,
( D = NmB ->
fail
; D = BmN ->
fail
;
true
),
D1 is D + 1,
nodiag(B, D1, L).

:- pred print_list(list(int), io__state, io__state).
:- mode print_list(in, di, uo) is det.

print_list(Xs) -->
(
{ Xs = [] }
->
io__write_string("[]\n")
;
io__write_string("["),
print_list_2(Xs),
io__write_string("]\n")
).

:- pred print_list_2(list(int), io__state, io__state).
:- mode print_list_2(in, di, uo) is det.

print_list_2([]) --> [].
print_list_2([X|Xs]) -->
io__write_int(X),
(
{ Xs = [] }
->
[]
;
io__write_string(", "),
print_list_2(Xs)
).

%-----------------------------------------------------------------------------%

GENERATED JAVA CODE

//
//
// Automatically generated from queens.m by the Mercury Compiler,
// version rotd-2002-10-09, configured for i686-pc-linux-gnu
//
//

/* :- module queens. */

import mercury.assoc_list;
import mercury.bool;
import mercury.builtin;
import mercury.mr_char;
import mercury.deconstruct;
import mercury.enum;
import mercury.mr_int;
import mercury.io;
import mercury.list;
import mercury.map;
import mercury.ops;
import mercury.private_builtin;
import mercury.set;
import mercury.std_util;
import mercury.string;
import mercury.term;
import mercury.time;
import mercury.tree234;
import mercury.type_desc;
import mercury.runtime.*;

public class queens {
public static void main(java.lang.String[] args)
{
mercury.runtime.JavaInternal.args = args;
queens.main_2_p_0();
return;
}

public static class AddrOf__queens__qperm_2_p_0_4_0
implements mercury.runtime.MethodPtr
{
public final java.lang.Object call___0_0(
java.lang.Object[] args)
{
{
java.lang.Object return_value = null;

{
queens.qperm_2_p_0_4(((queens.list_1) args[0]), ((java.lang.Object) args[1]));
}
return ((java.lang.Object) (return_value));
}
}

}

public static class AddrOf__queens__qperm_2_p_0_2_0
implements mercury.runtime.MethodPtr
{
public final java.lang.Object call___0_0(
java.lang.Object[] args)
{
{
java.lang.Object return_value = null;

{
queens.qperm_2_p_0_2(((java.lang.Integer) (args[0])).intValue(), ((queens.list_1) args[1]), ((java.lang.Object) args[2]));
}
return ((java.lang.Object) (return_value));
}
}

}

public static class AddrOf__queens__qdelete_3_p_0_2_0
implements mercury.runtime.MethodPtr
{
public final java.lang.Object call___0_0(
java.lang.Object[] args)
{
{
java.lang.Object return_value = null;

{
queens.qdelete_3_p_0_2(((java.lang.Integer) (args[0])).intValue(), ((queens.list_1) args[1]), ((java.lang.Object) args[2]));
}
return ((java.lang.Object) (return_value));
}
}

}

public static class AddrOf__queens__main_2_p_0_3_0
implements mercury.runtime.MethodPtr
{
public final java.lang.Object call___0_0(
java.lang.Object[] args)
{
{
java.lang.Object return_value = null;

{
queens.main_2_p_0_3(((queens.list_1) args[0]), ((java.lang.Object) args[1]));
}
return ((java.lang.Object) (return_value));
}
}

}

public static class list_1
{
public int data_tag = 0;
public static class f_cons_2
extends queens.list_1
{
public java.lang.Object F1 = null;
public queens.list_1 F2 = null;

public f_cons_2(
java.lang.Object F1,
queens.list_1 F2)
{
{
(this).data_tag = 1;
((queens.list_1.f_cons_2) (this)).F1 = F1;
((queens.list_1.f_cons_2) (this)).F2 = F2;
}
}
}

public static class f_nil_0
extends queens.list_1
{

public f_nil_0()
{
{
(this).data_tag = 0;
}
}
}


}

private static void print_list_2_3_p_0(
queens.list_1 HeadVar__1_1)
{
{
boolean succeeded = false;

if ((HeadVar__1_1.data_tag == 0))
{
}
else
{
int X_6 = (int) ((java.lang.Integer) (((queens.list_1.f_cons_2) HeadVar__1_1).F1)).intValue();
queens.list_1 Xs_7 = (queens.list_1) ((queens.list_1.f_cons_2) HeadVar__1_1).F2;

{
mercury.io.write_int_3_p_0(X_6);
}
succeeded = (Xs_7.data_tag == 0);
if (succeeded)
{
}
else
{
java.lang.String V_13_13 = (java.lang.String) ", ";

{
mercury.io.write_string_3_p_0(V_13_13);
}
{
queens.print_list_2_3_p_0(Xs_7);
}
}
}
return;
}
}
private static boolean nodiag_3_p_0(
int HeadVar__1_1,
int HeadVar__2_2,
queens.list_1 HeadVar__3_3)
{
while (true)
{
/* tailcall optimized into a loop */
{
boolean succeeded = false;

if ((HeadVar__3_3.data_tag == 0))
succeeded = true;
else
{
int N_8 = (int) ((java.lang.Integer) (((queens.list_1.f_cons_2) HeadVar__3_3).F1)).intValue();
queens.list_1 L_9 = (queens.list_1) ((queens.list_1.f_cons_2) HeadVar__3_3).F2;
int NmB_10 = (int) (N_8 - HeadVar__1_1);
int BmN_11 = (int) (HeadVar__1_1 - N_8);
int D1_12 = 0;
int V_13_13 = 0;

succeeded = (HeadVar__2_2 == NmB_10);
if (succeeded)
succeeded = false;
else
{
succeeded = (HeadVar__2_2 == BmN_11);
if (succeeded)
succeeded = false;
else
succeeded = true;
}
if (succeeded)
{
V_13_13 = 1;
D1_12 = (HeadVar__2_2 + V_13_13);
{
/* direct tailcall eliminated */
{
int HeadVar__2__tmp_copy_2 = (int) D1_12;
queens.list_1 HeadVar__3__tmp_copy_3 = (queens.list_1) L_9;

HeadVar__3_3 = HeadVar__3__tmp_copy_3;
HeadVar__2_2 = HeadVar__2__tmp_copy_2;
}
continue;
}
}
}
return succeeded;
}
}
}
private static boolean safe_1_p_0(
queens.list_1 HeadVar__1_1)
{
while (true)
{
/* tailcall optimized into a loop */
{
boolean succeeded = false;

if ((HeadVar__1_1.data_tag == 0))
succeeded = true;
else
{
int N_2 = (int) ((java.lang.Integer) (((queens.list_1.f_cons_2) HeadVar__1_1).F1)).intValue();
queens.list_1 L_3 = (queens.list_1) ((queens.list_1.f_cons_2) HeadVar__1_1).F2;
int V_4_4 = (int) 1;

{
succeeded = queens.nodiag_3_p_0(N_2, V_4_4, L_3);
}
if (succeeded)
{
/* direct tailcall eliminated */
{
queens.list_1 HeadVar__1__tmp_copy_1 = (queens.list_1) L_3;

HeadVar__1_1 = HeadVar__1__tmp_copy_1;
}
continue;
}
}
return succeeded;
}
}
}
private static class qdelete_3_p_0_env_0
extends java.lang.Object
{
public mercury.runtime.MethodPtr cont = null;
public java.lang.Object cont_env_ptr = null;
public int HeadVar__1_1 = 0;
public queens.list_1 HeadVar__3_3 = null;
public int V_11_11 = 0;
public queens.list_1 R_9 = null;

}

private static void qdelete_3_p_0_2(
int arg1,
queens.list_1 arg2,
java.lang.Object env_ptr_arg)
{
{
queens.qdelete_3_p_0_env_0 env_ptr = (queens.qdelete_3_p_0_env_0) (queens.qdelete_3_p_0_env_0) env_ptr_arg;

{
((queens.qdelete_3_p_0_env_0) env_ptr).HeadVar__1_1 = arg1;
((queens.qdelete_3_p_0_env_0) env_ptr).R_9 = arg2;
{
queens.qdelete_3_p_0_1(env_ptr);
}
}
}
}
private static void qdelete_3_p_0_1(
java.lang.Object env_ptr_arg)
{
{
queens.qdelete_3_p_0_env_0 env_ptr = (queens.qdelete_3_p_0_env_0) (queens.qdelete_3_p_0_env_0) env_ptr_arg;

{
{
((queens.qdelete_3_p_0_env_0) env_ptr).HeadVar__3_3 = new queens.list_1.f_cons_2(new java.lang.Integer(((queens.qdelete_3_p_0_env_0) env_ptr).V_11_11), ((queens.qdelete_3_p_0_env_0) env_ptr).R_9);
}
{
(((queens.qdelete_3_p_0_env_0) env_ptr).cont).call___0_0(new java.lang.Object[] { new java.lang.Integer(((queens.qdelete_3_p_0_env_0) env_ptr).HeadVar__1_1), ((java.lang.Object) (((queens.qdelete_3_p_0_env_0) env_ptr).HeadVar__3_3)), ((java.lang.Object) (((queens.qdelete_3_p_0_env_0) env_ptr).cont_env_ptr))} );
}
}
}
}
private static void qdelete_3_p_0(
queens.list_1 HeadVar__2_2,
mercury.runtime.MethodPtr cont,
java.lang.Object cont_env_ptr)
{
{
queens.qdelete_3_p_0_env_0 env = null;
queens.qdelete_3_p_0_env_0 env_ptr = null;

{
env = new queens.qdelete_3_p_0_env_0();
}
env_ptr = env;
((queens.qdelete_3_p_0_env_0) env_ptr).cont = cont;
((queens.qdelete_3_p_0_env_0) env_ptr).cont_env_ptr = cont_env_ptr;
{
boolean succeeded = (boolean) (HeadVar__2_2.data_tag == 1);
queens.list_1 V_10_10 = null;

if (succeeded)
{
((queens.qdelete_3_p_0_env_0) env_ptr).V_11_11 = ((java.lang.Integer) (((queens.list_1.f_cons_2) HeadVar__2_2).F1)).intValue();
V_10_10 = ((queens.list_1.f_cons_2) HeadVar__2_2).F2;
}
if (succeeded)
{
{
((queens.qdelete_3_p_0_env_0) env_ptr).HeadVar__1_1 = ((queens.qdelete_3_p_0_env_0) env_ptr).V_11_11;
((queens.qdelete_3_p_0_env_0) env_ptr).HeadVar__3_3 = V_10_10;
{
(((queens.qdelete_3_p_0_env_0) env_ptr).cont).call___0_0(new java.lang.Object[] { new java.lang.Integer(((queens.qdelete_3_p_0_env_0) env_ptr).HeadVar__1_1), ((java.lang.Object) (((queens.qdelete_3_p_0_env_0) env_ptr).HeadVar__3_3)), ((java.lang.Object) (((queens.qdelete_3_p_0_env_0) env_ptr).cont_env_ptr))} );
}
}
{
{
queens.qdelete_3_p_0(V_10_10, new AddrOf__queens__qdelete_3_p_0_2_0(), env_ptr);
}
}
}
}
}
}
private static class qperm_2_p_0_env_0
extends java.lang.Object
{
public mercury.runtime.MethodPtr cont = null;
public java.lang.Object cont_env_ptr = null;
public queens.list_1 HeadVar__2_2 = null;
public int U_6 = 0;
public queens.list_1 Z_7 = null;
public queens.list_1 V_8 = null;

}

private static void qperm_2_p_0_2(
int arg1,
queens.list_1 arg2,
java.lang.Object env_ptr_arg)
{
{
queens.qperm_2_p_0_env_0 env_ptr = (queens.qperm_2_p_0_env_0) (queens.qperm_2_p_0_env_0) env_ptr_arg;

{
((queens.qperm_2_p_0_env_0) env_ptr).U_6 = arg1;
((queens.qperm_2_p_0_env_0) env_ptr).Z_7 = arg2;
{
queens.qperm_2_p_0_1(env_ptr);
}
}
}
}
private static void qperm_2_p_0_4(
queens.list_1 arg1,
java.lang.Object env_ptr_arg)
{
{
queens.qperm_2_p_0_env_0 env_ptr = (queens.qperm_2_p_0_env_0) (queens.qperm_2_p_0_env_0) env_ptr_arg;

{
((queens.qperm_2_p_0_env_0) env_ptr).V_8 = arg1;
{
queens.qperm_2_p_0_3(env_ptr);
}
}
}
}
private static void qperm_2_p_0_3(
java.lang.Object env_ptr_arg)
{
{
queens.qperm_2_p_0_env_0 env_ptr = (queens.qperm_2_p_0_env_0) (queens.qperm_2_p_0_env_0) env_ptr_arg;

{
{
((queens.qperm_2_p_0_env_0) env_ptr).HeadVar__2_2 = new queens.list_1.f_cons_2(new java.lang.Integer(((queens.qperm_2_p_0_env_0) env_ptr).U_6), ((queens.qperm_2_p_0_env_0) env_ptr).V_8);
}
{
(((queens.qperm_2_p_0_env_0) env_ptr).cont).call___0_0(new java.lang.Object[] { ((java.lang.Object) (((queens.qperm_2_p_0_env_0) env_ptr).HeadVar__2_2)), ((java.lang.Object) (((queens.qperm_2_p_0_env_0) env_ptr).cont_env_ptr))} );
}
}
}
}
private static void qperm_2_p_0_1(
java.lang.Object env_ptr_arg)
{
{
queens.qperm_2_p_0_env_0 env_ptr = (queens.qperm_2_p_0_env_0) (queens.qperm_2_p_0_env_0) env_ptr_arg;

{
{
queens.qperm_2_p_0(((queens.qperm_2_p_0_env_0) env_ptr).Z_7, new AddrOf__queens__qperm_2_p_0_4_0(), env_ptr);
}
}
}
}
private static void qperm_2_p_0(
queens.list_1 HeadVar__1_1,
mercury.runtime.MethodPtr cont,
java.lang.Object cont_env_ptr)
{
{
queens.qperm_2_p_0_env_0 env = null;
queens.qperm_2_p_0_env_0 env_ptr = null;

{
env = new queens.qperm_2_p_0_env_0();
}
env_ptr = env;
((queens.qperm_2_p_0_env_0) env_ptr).cont = cont;
((queens.qperm_2_p_0_env_0) env_ptr).cont_env_ptr = cont_env_ptr;
{
boolean succeeded = false;

if ((HeadVar__1_1.data_tag == 0))
{
{
((queens.qperm_2_p_0_env_0) env_ptr).HeadVar__2_2 = new queens.list_1.f_nil_0();
}
{
(((queens.qperm_2_p_0_env_0) env_ptr).cont).call___0_0(new java.lang.Object[] { ((java.lang.Object) (((queens.qperm_2_p_0_env_0) env_ptr).HeadVar__2_2)), ((java.lang.Object) (((queens.qperm_2_p_0_env_0) env_ptr).cont_env_ptr))} );
}
}
else
{
{
queens.qdelete_3_p_0(HeadVar__1_1, new AddrOf__queens__qperm_2_p_0_2_0(), env_ptr);
}
}
}
}
}
private static class main_2_p_0_env_0
extends java.lang.Object
{
public boolean succeeded = false;
public queens.list_1 Out_4 = null;
public mercury.runtime.Commit commit_1 = null;

}

private static void main_2_p_0_1(
java.lang.Object env_ptr_arg)
{
{
queens.main_2_p_0_env_0 env_ptr = (queens.main_2_p_0_env_0) (queens.main_2_p_0_env_0) env_ptr_arg;

((queens.main_2_p_0_env_0) env_ptr).commit_1 = new mercury.runtime.Commit();
throw ((queens.main_2_p_0_env_0) env_ptr).commit_1;
}
}
private static void main_2_p_0_3(
queens.list_1 arg1,
java.lang.Object env_ptr_arg)
{
{
queens.main_2_p_0_env_0 env_ptr = (queens.main_2_p_0_env_0) (queens.main_2_p_0_env_0) env_ptr_arg;

{
((queens.main_2_p_0_env_0) env_ptr).Out_4 = arg1;
{
queens.main_2_p_0_2(env_ptr);
}
}
}
}
private static void main_2_p_0_2(
java.lang.Object env_ptr_arg)
{
{
queens.main_2_p_0_env_0 env_ptr = (queens.main_2_p_0_env_0) (queens.main_2_p_0_env_0) env_ptr_arg;

{
{
((queens.main_2_p_0_env_0) env_ptr).succeeded = queens.safe_1_p_0(((queens.main_2_p_0_env_0) env_ptr).Out_4);
}
if (((queens.main_2_p_0_env_0) env_ptr).succeeded)
{
queens.main_2_p_0_1(env_ptr);
}
}
}
}
public static void main_2_p_0()
{
{
queens.main_2_p_0_env_0 env = null;
queens.main_2_p_0_env_0 env_ptr = null;

{
env = new queens.main_2_p_0_env_0();
}
env_ptr = env;
{
queens.list_1 Data_3 = null;
int V_9_9 = (int) 1;
queens.list_1 V_10_10 = null;
int V_11_11 = (int) 2;
queens.list_1 V_12_12 = null;
int V_13_13 = (int) 3;
queens.list_1 V_14_14 = null;
int V_15_15 = (int) 4;
queens.list_1 V_16_16 = null;
int V_17_17 = (int) 5;
queens.list_1 V_18_18 = null;
int V_19_19 = (int) 6;
queens.list_1 V_20_20 = null;
int V_21_21 = (int) 7;
queens.list_1 V_22_22 = null;
int V_23_23 = (int) 8;
queens.list_1 V_24_24 = null;

{
V_24_24 = new queens.list_1.f_nil_0();
}
{
V_22_22 = new queens.list_1.f_cons_2(new java.lang.Integer(V_23_23), V_24_24);
}
{
V_20_20 = new queens.list_1.f_cons_2(new java.lang.Integer(V_21_21), V_22_22);
}
{
V_18_18 = new queens.list_1.f_cons_2(new java.lang.Integer(V_19_19), V_20_20);
}
{
V_16_16 = new queens.list_1.f_cons_2(new java.lang.Integer(V_17_17), V_18_18);
}
{
V_14_14 = new queens.list_1.f_cons_2(new java.lang.Integer(V_15_15), V_16_16);
}
{
V_12_12 = new queens.list_1.f_cons_2(new java.lang.Integer(V_13_13), V_14_14);
}
{
V_10_10 = new queens.list_1.f_cons_2(new java.lang.Integer(V_11_11), V_12_12);
}
{
Data_3 = new queens.list_1.f_cons_2(new java.lang.Integer(V_9_9), V_10_10);
}
try
{
{
{
{
queens.qperm_2_p_0(Data_3, new AddrOf__queens__main_2_p_0_3_0(), env_ptr);
}
}
((queens.main_2_p_0_env_0) env_ptr).succeeded = false;
}
}
catch (mercury.runtime.Commit commit_variable)
{
((queens.main_2_p_0_env_0) env_ptr).succeeded = true;
}
if (((queens.main_2_p_0_env_0) env_ptr).succeeded)
{
((queens.main_2_p_0_env_0) env_ptr).succeeded = ((((queens.main_2_p_0_env_0) env_ptr).Out_4).data_tag == 0);
if (((queens.main_2_p_0_env_0) env_ptr).succeeded)
{
java.lang.String V_33_33 = (java.lang.String) "[]\n";

{
mercury.io.write_string_3_p_0(V_33_33);
}
}
else
{
java.lang.String V_34_34 = (java.lang.String) "[";
java.lang.String V_35_35 = null;

{
mercury.io.write_string_3_p_0(V_34_34);
}
{
queens.print_list_2_3_p_0(((queens.main_2_p_0_env_0) env_ptr).Out_4);
}
V_35_35 = "]\n";
{
mercury.io.write_string_3_p_0(V_35_35);
}
}
}
else
{
java.lang.String V_8_8 = (java.lang.String) "No solution\n";

{
mercury.io.write_string_3_p_0(V_8_8);
}
}
return;
}
}
}
}
// :- end_module queens.
--
Fergus Henderson <f...@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.

Josh Stern

unread,
Oct 10, 2002, 2:01:58 PM10/10/02
to
In <ao3vh1$j58vo$1...@ID-8247.news.dfncis.de>, Henrique Seganfredo wrote:

> Hi folks, where can I find a prolog converter to Java? I have a simple
> program here that I would like to see its size and complexity in Java...

Hi, the question is a bit hard to interpret. Do you mean that
you would like to see a) a small Java program with exactly
the same I/O behavior or b) a Java program with some implicit,
but unstated mapping, from the clauses of your particular Prolog
program to Java objects (e.g. there is some sort of homomorphism
between the call graph of the two) or c) a Prolog interpreter
written in Java that uses Java classes for Prolog types, or d)
is it something else?

For c) with some hints that my help with b) you can look at
Paul Tarau's Jinni program:

http://www.binnetcorp.com/OpenCode/kprolog/Main.html


-= Josh

Bart Demoen

unread,
Oct 10, 2002, 3:44:59 PM10/10/02
to
Fergus Henderson wrote:

> The Mercury compiler has some experimental support for compiling
> Mercury to Java. As far as I know this is the only implementation
> which really translates logic programming code to Java, rather than
> e.g. translating to WAM and writing a WAM interpreter in Java.

I am not sure I know exactly what "really translating LP code to Java",
means but ...
in 1996, Paul Tarau and myself made an implementation of most of
Prolog, by compiling Prolog to Java - no WAM interpreter involved.
Admittedly, there was a WAM like choicepoint stack and a trail, but
no WAM instructions and no WAM environment stack, neither a WAM heap.
Because we didn't (couldn't) count on tail recursion
optimization in Java, we followed a trampoline model of execution and
we actually compiled binarized Prolog clauses. The thing was named
jProlog and is still available at http://www.cs.kuleuven.ac.be/~bmd/PrologInJava/
Paul and I did this little project to learn Java :-)
It doesn't do all of Prolog (no dynamic predicates) but at some point it had intuitionistic
assumption, backtrackable destructive assignment and freeze; i
t is highly non-optimized: no indexing for instance.
Other systems have followed a similar approach to compiling Prolog to Java,
if I remember well http://Prolog.isac.co.jp/jipl/index_e.html is one of them.
I don't know enough about other systems to claim that jProlog was the first
Prolog to Java compiler or the first Prolog in Java implementation, but I have
never heard about an earlier system.

Two years ago, two students here (Ruben Vandeginste and Peter Vanbroekhoven,
supervised by Gerda Janssens) compiled Prolog to Java in a way more inspired
by OO. The result was a beautiful entanglement of objects, where even cut was
send as a message to whomever it concerned. I don't know if any of it is still sitting
somewhere ...

Cheers

Bart Demoen

Henrique Seganfredo

unread,
Oct 10, 2002, 8:21:04 PM10/10/02
to
I've run across your PrologInJava, and found it could suit my needs, but I
tried to make it work here and got no success at all...

see:

C:\TEMP\jprolog>java Prolog
jProlog 0.1 Copyright (C) Bart Demoen, Paul Tarau 1996
?- comp(familia.pl).
?- comp('familia.pl').
Predicate comp/1 not found; does its .class file exist ?
?-

the familia.pl file is located in the same directory as jprolog

I've read the docs where it was mentioned that I could convert a prolog
program into java by using 'comp'....what I did wrong? do I need something
else besides the jprolog files and a JVM?

--
Henrique Seganfredo (Segao)

henrique at seganfredo dot com
ICQ 340812

computer geek

"Quanto mais aprendo, menos eu sei"
"The more I learn, the less I know"

"Bart Demoen" <b...@cs.kuleuven.ac.be> wrote in message
news:3DA5D8BB...@cs.kuleuven.ac.be...

Bart Demoen

unread,
Oct 11, 2002, 6:56:17 AM10/11/02
to
Henrique Seganfredo wrote:

> I've run across your PrologInJava, and found it could suit my needs, but I
> tried to make it work here and got no success at all...
>
> see:
>
> C:\TEMP\jprolog>java Prolog
> jProlog 0.1 Copyright (C) Bart Demoen, Paul Tarau 1996
> ?- comp(familia.pl).
> ?- comp('familia.pl').
> Predicate comp/1 not found; does its .class file exist ?
> ?-
>
> the familia.pl file is located in the same directory as jprolog

It is not complaining about not finding your Prolog file ...


> I've read the docs where it was mentioned that I could convert a prolog
> program into java by using 'comp'....what I did wrong? do I need something
> else besides the jprolog files and a JVM?

Seems like our README is not clear enough about that issue: jProlog was never
bootstrapped, so the compiler (from your Prolog source code to Java) is not itself
to be run in jProlog. You need another Prolog system for that - at the time of writing the
README, the situation was:

> To use the Prolog to Java compiler
> ----------------------------------
>
> You need a Prolog system (SICStus, BinProlog, BIMprolog are ok - SWI
> doesn't work apparently - for info on freely available BinProlog,
> contact Paul Tarau: tar...@umoncton.ca)
>
> To compile a Prolog file to Java:
>
> prolog comp
> ?- comp(file) .

(Paul is no longer at the university of Moncton - since many years - you can see how
old the documentation is - there is a good chance that SWI will work now: it was something
silly related to DEC-10 style I/O; I would think that most Prolog systems will work.)

So for instance, you could do:

SICStus -l comp % the -l option makes SICStus load the file on the command line
?- comp(file).

or

SICStus
?- compile(comp). % this one for loading the compiler into SICStus
?- comp(file).


Hope this helps

Bart Demoen

Alexei A. Morozov

unread,
Oct 11, 2002, 11:04:36 AM10/11/02
to
Hi,

See also:

(1) The Web site of Anton Eliens and Zhisheng Huang
http://www.cs.vu.nl/~eliens/research/logic/index.html.

(2) Net Prolog created by Cedric Luiz de Carvalho.
http://netprolog.pdc.dk/. (Source files written in Visual Prolog are
available.)

Best regards,

Alexei A. Morozov

agarwal...@gmail.com

unread,
Mar 2, 2017, 12:35:33 PM3/2/17
to
Hey guys I have just started learning prolog, however I want to know how I can write my prolog generated code to a Java .class file and then run it in a JVM??

rupert...@googlemail.com

unread,
Mar 3, 2017, 7:21:42 AM3/3/17
to
On Thursday, March 2, 2017 at 5:35:33 PM UTC, agarwal...@gmail.com wrote:
> Hey guys I have just started learning prolog, however I want to know how I can write my prolog generated code to a Java .class file and then run it in a JVM??

http://drops.dagstuhl.de/opus/volltexte/2011/3176/pdf/19.pdf

polymorph self

unread,
Mar 8, 2017, 8:16:59 PM3/8/17
to
Better to convert your java programs into prolog?

agarwal...@gmail.com

unread,
Mar 9, 2017, 4:39:03 PM3/9/17
to
Well this doesn't resolve my problem..


What I am looking for If I write a code in projog/projog, how do I convert it to java source file and java class file.

agarwal...@gmail.com

unread,
Mar 9, 2017, 4:40:25 PM3/9/17
to
nah! I am working on project where in I have to convert prolog/projog code to either java source file or java class file. In a way I want create java source code using prolog/projog
0 new messages