Just found a nice implementation of Prolog in Scala. Unfortunately I didn t have time to try it, so my impression is only based on looking at the source code that can be found here:
https://github.com/sonoisa/Prolog-in-Scala/blob/master/PrologInScalaSample.scala
The above points to a couple of test programs. The Prolog interpreter is written in Scala in such a way that Prolog clauses can be embedded as Scala objects written in Scala. I don t fully understand the magic behind it, here is a sample how the tak function is written:
tak( X, Y, Z, A) :- (
X =< Y, CUT, Z === A)
tak( X, Y, Z, A) :- (
X1 is X - 1,
Y1 is Y - 1,
Z1 is Z - 1,
tak( X1, Y, Z, A1),
tak( Y1, Z, X, A2),
tak( Z1, X, Y, A3),
tak( A1, A2, A3, A)
)
I guess it is doing backtracking via continuations and has its own
implementation of a variable environment and unification.
If you look at the code, for example of unifyTerm, you will see that it
makes heavily use of pattern matching, which puts Scala into a special
position for implementing logic engines.
Best Regards