1 | /* |
---|
2 | * MainAlternative.java |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Ville Voutilainen |
---|
5 | * $Id: MainAlternative.java 14570 2013-07-22 13:21:06Z mevenson $ |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License |
---|
9 | * as published by the Free Software Foundation; either version 2 |
---|
10 | * of the License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software |
---|
19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | import org.armedbear.lisp.Function; |
---|
23 | import org.armedbear.lisp.Interpreter; |
---|
24 | import org.armedbear.lisp.Package; |
---|
25 | import org.armedbear.lisp.Packages; |
---|
26 | import org.armedbear.lisp.Symbol; |
---|
27 | |
---|
28 | public class MainAlternative |
---|
29 | { |
---|
30 | /** |
---|
31 | * This example creates an Interpreter instance, loads our |
---|
32 | * lisp code from a file and then looks up a function defined |
---|
33 | * in the loaded lisp file and executes the function. |
---|
34 | */ |
---|
35 | public static void main(String[] argv) |
---|
36 | { |
---|
37 | try |
---|
38 | { |
---|
39 | Interpreter interpreter = Interpreter.createInstance(); |
---|
40 | interpreter.eval("(load \"lispfunction.lisp\")"); |
---|
41 | // the function is not in a separate package, thus the |
---|
42 | // correct package is CL-USER. Symbol names are |
---|
43 | // (usually) upper case. |
---|
44 | Package defaultPackage |
---|
45 | = Packages.findPackage("CL-USER"); |
---|
46 | Symbol sym |
---|
47 | = defaultPackage.findAccessibleSymbol("LISPFUNCTION"); |
---|
48 | Function function = (Function) sym.getSymbolFunction(); |
---|
49 | function.execute(); |
---|
50 | } |
---|
51 | catch (Throwable t) |
---|
52 | { |
---|
53 | System.out.println("exception!"); |
---|
54 | t.printStackTrace(); |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|