3APL-M Logo 3APL-M
Platform for Lightweight Deliberative Agents



::: mProlog: Lightweight PROLOG Engine :::

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)

download mprolog-src.zip

mProlog JavaDoc

hyperlink mProlog JavaDoc

mProlog for J2SE

Compilation environment: java version "1.4.1_02" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06) Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
download mprolog-j2se.jar

mProlog for J2ME

Compilation environment: java version "1.4.1_02" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06) Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode) J2ME Wireless Toolkit 2.1 Profile: MIDP-2.0 Configuration: CLDC-1.1 Optional: WMA-1.1,MMAPI-1.1,JSR172,JSR185 (JTWI)
download mprolog-j2me.jar

Built-in predicates

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();
}
}

download 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)");

PrologTerm goal = PrologTerm.create("granmother(a,WHO)");
PrologQuery query = new PrologQuery(prolog, goal);
PrologTerm[] solution = query.solution();
while(solution!=null){
System.out.println(solution[0].getVariableName()+"->"+ solution[0].getVariableValue());
solution = query.solution();
}

System.out.println("-- Statistics --");
System.out.println("UNIFICATIONS=>"+prolog.getTotalNumberUnifications());
System.out.println("QUERIES=>"+prolog.getTotalNumberQueries());
System.out.println("TIME=>"+prolog.getExecutionTime());
System.out.println("-- Knowledge Base --");
System.out.println(prolog.toString());
}
}

download MPrologTest002.java

Code example: Handling numbers

import mProlog.*;

public class MPrologTest003 {
public static void main(String[] args) {
PrologEngine prolog = new PrologEngine();
prolog.add("add(A,B,RESULT):- eq(RESULT,A+B)");
PrologTerm goal = PrologTerm.create("add(10,20,RESULT)");
PrologQuery query = new PrologQuery(prolog, goal);
PrologTerm[] solution = query.solution();
if(solution!=null){
System.out.println(solution[0].getVariableName()+"->"+ solution[0].getVariableValue());

solution = query.solution();
}
}
}

download MPrologTest003.java

Code example: Handling lists

import mProlog.*;

public class MPrologTest004 {
public static void main(String[] args) {
PrologEngine prolog = new PrologEngine();
prolog.add("addList(A,ELEMENT,RESULT):- eq(RESULT,A+ELEMENT)");
PrologTerm goal = PrologTerm.create("addList([a,b],c,RESULT)");
PrologQuery query = new PrologQuery(prolog, goal);
PrologTerm[] solution = query.solution();
if(solution!=null){
System.out.println(solution[0].getVariableName()+"->"+ solution[0].getVariableValue());

solution = query.solution();
}
}
}

download MPrologTest004.java

3APL-M: Platform for Lightweight Deliberative Agents
Powered by XML and XSLT.
Last updated: Thu Jul 28 19:50:57 CEST 2005