mProlog is a sub-product of the 3APL-M project. It delivers a reduced Prolog engine, optimized for J2ME applications. The mProlog engine was developed based on the
W-Prolog
project from Michael Winikoff. The code was heavily re-engineered and contains several methods that facilitate the 3APL integration. However, the interface is broad enough to allow the integration to any other Java application. mProlog is distributed as binary and source code, protected by the
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991.
mProlog is distributed without documentation other than the JavaDoc (it's supposed to be an embedded product). Use at your own risk but I am willing to help in any project. It is very easy to integrate mProlog to any Java application. I am providing some code examples in this page. If you need any further help, don't hesitate to drop me an email!
If you find a bug or optimization, please drop me an email (check the
Contact
page)
mProlog current version: v3.1.1 Mar-2005
mProlog source code
Protected by the
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991.
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program...
(see the rest of the terms at http://www.gnu.org/licenses/gpl.txt)
eq(X,X). // true if X equals to Y (or assign X to Y or vice versa)
and(X,Y).
or(X,Y).
call(X,Y).
assert(X). // add predicate X to knowledge base
retract(X). // remove predicate X from knowledge base
random(MAX, X). // generate random number from 0 to MAX
random(MIN, MAX, X). // generate random number from MIN to MAX
write(X). // print X to STDOUT
nl. // print new-line to STDOUT
write(Stream, X). // print X to a Stream (pre-open by Java code)
if(X,Y,Z). // if X is true, execute Y, otherwise execute Z.
Code example: Hello World
import mProlog.*;
public class MPrologTest001 {
public static void main(String[] args) {
PrologEngine prolog = new PrologEngine();
PrologTerm goal = PrologTerm.create("write('Hello World\n')");
PrologQuery query = new PrologQuery(prolog, goal);
PrologTerm[] solution = query.solution();
}
}
MPrologTest001.java
Code example: Family tree
import mProlog.*;
public class MPrologTest002 {
public static void main(String[] args) {
Tracer.set("prolog",3);
PrologEngine prolog = new PrologEngine();
prolog.add("mother(a,b)");
prolog.add("mother(b,c)");
prolog.add("mother(b,d)");
prolog.add("mother(e,f)");
prolog.add("granmother(A,B):-mother(A,C),mother(C,B)");