1 package scm; 3 4 class Cell implements Obj 5 { 6 Obj car; 7 Cell cdr; public Obj eval(Env e) 11 throws Exception 12 { 13 Procedure p; 14 15 if (car == null) 16 { throw new SchemeError("null car cell trying to eval " + this); } 17 18 if (car instanceof Procedure) 19 { p = (Procedure) car; } 20 else 21 { p = (Procedure) car.eval(e); } 22 23 return (p.apply(cdr, e)); } 26 27 Cell (Obj a, Cell b) 28 { car = a; cdr = b; } 29 30 public String toString() 31 { 32 return toString(""); 33 } 34 public String toString(String s) 35 { 36 if (car == null) { s += "()"; } 37 else 38 { s += car.toString(); } 39 40 if (cdr == null) 41 { return ( "(" + s + ")"); } 42 else 43 { return (cdr.toString(s + " ")); } 44 } 45 } 46 47 | Popular Tags |