HelloWorld.java

00001 package com.declarativa.interprolog.examples;
00002 import com.declarativa.interprolog.*;
00003 import com.xsb.interprolog.*;
00004 public class HelloWorld{
00005         public static void main(String args[]) {
00006                 PrologEngine engine = new NativeEngine(args[0]);
00007                 engine.command("import append/3 from basics");
00008                 Object[] bindings = engine.deterministicGoal(
00009                         "name(User,UL),append(\"Hello,\", UL, ML), name(Message,ML)",
00010                         "[string(User)]",
00011                         new Object[]{System.getProperty("user.name")},
00012                         "[string(Message)]");
00013                 String message = (String)bindings[0];
00014                 System.out.println("\nMessage:"+message);
00015                 // the above demonstrates object passing both ways; 
00016                 // since we may simply concatenate strings, an alternative coding would be:
00017                 bindings = engine.deterministicGoal(
00018                         "name('"+System.getProperty("user.name")+"',UL),append(\"Hello,\", UL, ML), name(Message,ML)",
00019                         "[string(Message)]");
00020                 // (notice the ' surrounding the user name, unnecessary in the first case)
00021                 System.out.println("Same:"+bindings[0]);
00022                 System.exit(0);
00023         }
00024 }

Generated on Wed Jul 26 13:30:44 2006 for XSB by  doxygen 1.4.5