1- package java ;
21
32import java .io .FileInputStream ;
43import java .io .IOException ;
@@ -57,6 +56,7 @@ public void readEvalWriteLoop() {
5756 output .print ("> " );
5857 output .flush ();
5958 if (input .isEOF (x = input .read ())) return ;
59+ x = expand (x );
6060 write (eval (x ), output , true );
6161 output .println ();
6262 output .flush ();
@@ -85,6 +85,7 @@ public Object load(InputPort in) {
8585 Object x = null ;
8686 for (; ; ) {
8787 if (in .isEOF (x = in .read ())) return TRUE ;
88+ x = expand (x );
8889 eval (x );
8990 }
9091 }
@@ -106,7 +107,10 @@ public Object eval(Object x, Environment env) {
106107 } else {
107108 Object fn = first (x );
108109 Object args = rest (x );
109- if (fn == "quote" ) { // QUOTE
110+ if (fn == "quote" ) { // QUOTE
111+ if (rest (args ) != null ) {
112+ error ("Quote only accepts one argument got " + args );
113+ }
110114 return first (args );
111115 } else if (fn == "begin" ) { // BEGIN
112116 for (; rest (args ) != null ; args = rest (args )) {
@@ -121,6 +125,9 @@ public Object eval(Object x, Environment env) {
121125 } else if (fn == "set!" ) { // SET!
122126 return env .set (first (args ), eval (second (args ), env ));
123127 } else if (fn == "if" ) { // IF
128+ if (length (args ) > 3 ) {
129+ error ("if accepts only three arguments at most got " + args );
130+ }
124131 x = (truth (eval (first (args ), env ))) ? second (args ) : third (args );
125132 } else if (fn == "cond" ) { // COND
126133 x = reduceCond (args , env );
@@ -155,7 +162,7 @@ public Object eval(Object x) {
155162 * Eval a String
156163 */
157164 public Object eval (String str ) {
158- return eval (( new InputPort (new StringReader (str ))).read ());
165+ return eval (expand (( new InputPort (new StringReader (str ))).read () ));
159166 }
160167
161168 /**
@@ -191,6 +198,11 @@ else if (second(clause) == "=>")
191198 }
192199 }
193200
201+
202+ private Object expand (Object x ) {
203+ return x ;
204+ }
205+
194206}
195207
196208
0 commit comments