2

Say I am interested in creating a JVM-based implementation of Prolog. I would like to know if it is possible to use an existing JVM language for emulating the Prolog syntax, instead of relying on a Prolog parser that takes as an input a text file with Prolog code.

In Prolog you can define facts, rules, and the tricky part is that you can also define new operators at a very fine-grained level: you can specify the operator position, precedence and associativity.

Some simple examples below:

Facts:

father(john, peter).
mother(susan, peter).
male(john).
...

Rules:

parent(X, Y) :- father(X, Y).
parent(X, Y) :- mother(X, Y).

Operators:

op(100,xfx, is-father-of)

Rule using operator:

X is-father-of Y :- male(X), parent(X,Y).

I took a look to Groovy but it does not seem to allow to define new operators. To the best of my knowledge Scala allows to define operators but I do not think a statically-typed language will help me here. Is there a JVM language that could help me to do this?

Am I condemned to make use of a Prolog parser if I want to do this in the JVM?

Community
  • 1
  • 1
Sergio
  • 8,532
  • 11
  • 52
  • 94
  • 3
    This is a wild guess, but parsing Prolog is going to be one of the easier things to do. Implementing a (working) Prolog VM in on top of the JVM is quite a task. –  Mar 20 '16 at 10:58
  • I know it pretty well. And I am not saying that I will actually end up doing it :) . It is just a question asked out of curiosity. – Sergio Mar 20 '16 at 11:02
  • 2
    You can always check out JIProlog, which is rather a Prolog implementation in Java (not a JVM Prolog), but I guess it should be possible to reuse some of their code. –  Mar 20 '16 at 11:09
  • Why do you think a statically-typed language won't help you? I think to the contrary. – Ingo Oct 07 '16 at 20:56

0 Answers0