001: /*
002: * Jatha - a Common LISP-compatible LISP library in Java.
003: * Copyright (C) 1997-2005 Micheal Scott Hewett
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: *
020: * For further information, please contact Micheal Hewett at
021: * hewett@cs.stanford.edu
022: *
023: */
024: /* Copyright (c) 1996, 1997 Micheal Hewett hewett@cs.stanford.edu
025: *
026: * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
027: * This source code is copyrighted as shown above. If this
028: * code was obtained as part of a freeware or shareware release,
029: * assume that the provisions of the Gnu "copyleft" agreement
030: * apply.
031: * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
032: *
033: * File: LispValueTest.java
034: *
035: * Author: Micheal Hewett
036: * Created: 13 Jan 1997
037: *
038: * Compiler: javac 1.0.2
039: *
040: * Description: Test program for the LispValue package
041: *
042: ****************************************************************************
043: *
044: * Classes:
045: *
046: * LispValueTest (has a main() function).
047: *
048: *
049: ****************************************************************************
050: */
051:
052: package org.jatha.test;
053:
054: import java.applet.Applet;
055: import java.io.IOException;
056:
057: import org.jatha.Jatha;
058: import org.jatha.dynatype.LispInteger;
059: import org.jatha.dynatype.LispReal;
060: import org.jatha.dynatype.LispString;
061: import org.jatha.dynatype.LispSymbol;
062: import org.jatha.dynatype.LispValue;
063:
064: public class LispValueTest extends Applet {
065: public static void main(String argv[]) {
066: LispTester tester = new LispTester();
067:
068: Jatha lisp = new Jatha(false, false);
069:
070: lisp.init();
071: lisp.start();
072:
073: tester.test(lisp);
074: }
075:
076: }
077:
078: class LispTester {
079:
080: public void show(String label, LispValue value) {
081: System.out.print(label);
082: value.print(); // System.out;
083: System.out.println();
084: }
085:
086: public void test(Jatha lisp) {
087:
088: // TEST SYMBOLS
089: LispSymbol x1 = lisp.makeSymbol("Mike");
090:
091: LispValue l1 = lisp.makeCons(x1, lisp.T);
092: LispValue l2 = lisp.makeCons(lisp.NIL, l1);
093:
094: show("L2: ", l2);
095:
096: LispValue l3 = lisp.makeCons(x1, lisp.NIL);
097: LispValue l4 = lisp.makeCons(lisp.T, l3);
098:
099: show("L4: ", l4);
100:
101: LispValue l5 = lisp.makeCons(x1, lisp.NIL);
102: LispValue l6 = lisp.makeCons(l3, l1);
103:
104: show("L6: ", l6);
105:
106: // TEST Numbers
107:
108: LispInteger i1 = lisp.makeInteger();
109: LispInteger i2 = lisp.makeInteger(5);
110: LispInteger i3 = lisp.makeInteger(273);
111:
112: LispValue l7 = lisp.makeCons(i3, lisp.makeList(i2, i1));
113: show("L7: ", l7);
114:
115: LispReal r1 = lisp.makeReal();
116: LispReal r2 = lisp.makeReal(5.5);
117: LispReal r3 = lisp.makeReal(273.273273);
118:
119: LispValue l8 = lisp.makeList(r3, r2, r1);
120: show("L8: ", l8);
121:
122: // TEST Strings
123:
124: LispString s1 = lisp.makeString("BAZ");
125: LispString s2 = lisp.makeString("bar");
126: LispString s3 = lisp.makeString("foo");
127:
128: LispValue l9 = lisp.makeCons(s3, lisp.makeCons(s2, lisp
129: .makeCons(s1, lisp.makeList(r3, r2, r1))));
130: show("L9: ", l9);
131:
132: LispValue l10 = lisp.makeList(s3, s2);
133: show("L10: ", l10);
134:
135: // Added 23 Feb 2006 (mh)
136: // try {
137: // String expr = "(* 5 B)";
138: // LispValue a = lisp.makeSymbol("A");
139: // a.set_special(true);
140: // a.setf_symbol_value(lisp.makeInteger(7));
141: // System.out.println("A = " + a.symbol_value());
142: //
143: // LispValue B = lisp.eval("B");
144: // LispValue globals = lisp.makeList(lisp.makeList(lisp.makeCons(lisp.makeSymbol("B"), lisp.makeInteger(7))));
145: // LispValue input = lisp.parse(expr);
146: // LispValue result = lisp.eval(input, globals);
147: // System.out.println(input + " = " + result);
148: // } catch (IOException ioe) {
149: // System.err.println("Exception during test ");
150: // }
151:
152: // Test #1
153: System.out.println(lisp.eval("(let ((x 7)) (* 5 x)))"));
154: System.out.println(lisp.eval("(progn (setq x 7) (* 5 x))"));
155: System.out.println(lisp.eval("(setq x 7)"));
156: System.out.println(lisp.eval("(* 5 x)"));
157:
158: // Test #2
159: try {
160: String expr = "(let ((x 7)) (* 5 x)))";
161: LispValue input = lisp.parse(expr);
162: LispValue result = lisp.eval(input);
163: System.out.println(input + " = " + result);
164: } catch (IOException ioe) {
165: System.err.println("Exception during test ");
166: }
167:
168: }
169: }
170:
171: /*
172:
173: void
174: cSimbaApp::test_lisp_functions(void)
175: {
176: // Test LISP functions
177:
178: LispString str1 = new LispString("testing");
179: cout << (char )(str1) << endl;
180:
181: cout << "Mike = " << (long)(intern("Mike")) << endl;
182: cout << "Mike = " << (long)(intern("Mike")) << endl;
183:
184: LispValue aList = list(3, lisp.makeCons(intern("Mike"), makeInteger(38)),
185: lisp.makeCons(intern("Allie"), makeInteger(4)),
186: lisp.makeCons(intern("Sowmya"), makeInteger(29)));
187: cout << "ALIST = " << aList << endl;
188:
189: LispValue value = assoc(intern("Mike"), aList);
190: cout << "Assoc returned: " << value << endl;
191:
192: LispValue list4 = list(5, intern("Alpha"), intern("Beta"), intern("Delta"), intern("Gamma"), intern("Zeta"));
193: cout << "Member(Beta) returned: " << (member(intern("Beta"), list4)) << endl;
194: cout << "Member(Tau) returned: " << (member(intern("Tau"), list4)) << endl;
195:
196: cout << "remove(Beta) returned: " << (remove(intern("Beta"), list4)) << endl;
197: cout << "remove(Tau) returned: " << (remove(intern("Tau"), list4)) << endl;
198:
199: cout << "remove(Alpha) returned: " << (remove(intern("Alpha"), list4)) << endl;
200: cout << "remove(Zeta) returned: " << (remove(intern("Zeta"), list4)) << endl;
201:
202: cout << "subst(Delta, Mike) returned: " << (subst(intern("Delta"), intern("Mike"), list4)) << endl;
203: cout << "subst(Foo, Mike) returned: " << (subst(intern("Foo"), intern("Mike"), list4)) << endl;
204: cout << "subst(Gamma, Allie) returned: " << (subst(intern("Gamma"), intern("Allie"), list4)) << endl;
205:
206: }
207:
208: */
|