| 1 | package program; |
|---|
| 2 | |
|---|
| 3 | import org.armedbear.lisp.Cons; |
|---|
| 4 | import org.armedbear.lisp.Fixnum; |
|---|
| 5 | import org.armedbear.lisp.Function; |
|---|
| 6 | import org.armedbear.lisp.Interpreter; |
|---|
| 7 | import org.armedbear.lisp.JavaObject; |
|---|
| 8 | import org.armedbear.lisp.LispObject; |
|---|
| 9 | import org.armedbear.lisp.MacroObject; |
|---|
| 10 | import org.armedbear.lisp.Packages; |
|---|
| 11 | import org.armedbear.lisp.Package; |
|---|
| 12 | import org.armedbear.lisp.Symbol; |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | public class Main { |
|---|
| 17 | public static void main(String[] args){ |
|---|
| 18 | //testABCL(); |
|---|
| 19 | loadTmSparql(); |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | public static void testABCL(){ |
|---|
| 24 | // load the file functions.lisp which also evaluates a let as last command |
|---|
| 25 | Interpreter interpreter = Interpreter.createInstance(); |
|---|
| 26 | interpreter.eval("(load \"lisp-code/test-code/functions.lisp\")"); |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | // use the lisp function print-line |
|---|
| 30 | Package defaultPackage = Packages.findPackage("CL-USER"); |
|---|
| 31 | Symbol myFunctionSym = defaultPackage.findAccessibleSymbol("PRINT-LINE"); |
|---|
| 32 | Function printLineFun = (Function)myFunctionSym.getSymbolFunction(); |
|---|
| 33 | LispObject lispString = JavaObject.getInstance("This is a java string", true); |
|---|
| 34 | printLineFun.execute(lispString); |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | // use the lisp function add |
|---|
| 38 | myFunctionSym = defaultPackage.findAccessibleSymbol("ADD"); |
|---|
| 39 | Function addFun = (Function)myFunctionSym.getSymbolFunction(); |
|---|
| 40 | LispObject lispInt1 = JavaObject.getInstance(6, true); |
|---|
| 41 | LispObject lispInt2 = JavaObject.getInstance(2, true); |
|---|
| 42 | LispObject result = addFun.execute(lispInt1, lispInt2); |
|---|
| 43 | System.out.println(result.intValue()); |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | // use the build-i function cons |
|---|
| 47 | myFunctionSym = defaultPackage.findAccessibleSymbol("CONS"); |
|---|
| 48 | Function consFun = (Function)myFunctionSym.getSymbolFunction(); |
|---|
| 49 | Cons list = (Cons) consFun.execute(Fixnum.getInstance(64), Fixnum.getInstance(65)); |
|---|
| 50 | System.out.println(list.car.intValue() + ", " + list.cdr.intValue()); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | public static void loadTmSparql(){ |
|---|
| 55 | // === load base-tools.lisp =========================================== |
|---|
| 56 | Interpreter interpreter = Interpreter.createInstance(); |
|---|
| 57 | interpreter.eval("(load \"lisp-code/base-tools/base-tools.lisp\")"); |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | // === load sparql.lisp =============================================== |
|---|
| 61 | //interpreter.eval("(load \"lisp-code/TM-SPARQL/sparql.lisp\")"); |
|---|
| 62 | //TODO: import datamodel => implement an abstract datamodel |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | // === test the loaded files ========================================== |
|---|
| 66 | Package defaultPackage = Packages.findPackage("BASE-TOOLS"); |
|---|
| 67 | Symbol myFunSym = defaultPackage.findAccessibleSymbol("separate-leading-digits".toUpperCase()); |
|---|
| 68 | Function strFun = (Function)myFunSym.getSymbolFunction(); |
|---|
| 69 | |
|---|
| 70 | LispObject str1 = JavaObject.getInstance("no leading digits in this string", true); |
|---|
| 71 | LispObject str2 = JavaObject.getInstance("123 string started with 3 digits", true); |
|---|
| 72 | System.out.println(strFun.execute(str1)); |
|---|
| 73 | System.out.println(strFun.execute(str2)); |
|---|
| 74 | } |
|---|
| 75 | } |
|---|