1
2
3
4
5
6
7
8
9
10
11
12class Pair extends SExpr {
13
14 protected final
15 SExpr left,right;
16
17
18
19 public
20 Pair(SExpr left) {
21 this.left = left;
22 this.right = nil;
23 }
24
25 public
26 Pair(SExpr left, SExpr right) {
27 this.left = left;
28 this.right = right;
29 }
30
31
32
33 public
34 SExpr car() {
35 return
36 left;
37 }
38
39 public
40 SExpr cdr() {
41 return
42 right;
43 }
44
45
46
47 public
48 SExpr isPair() {
49 return
50 t;
51 }
52
53
54
55
56 public
57 SExpr isList() {
58 return
59 right.isList();
60 }
61
62
63
64 public
65 SExpr isEqual(SExpr e2) {
66 if ( this == e2 )
67 return
68 t;
69
70 if ( ! ( e2 instanceof Pair ) )
71 return
72 nil;
73
74 {
75 Pair l2 = (Pair)e2;
76
77 if ( left.isEqual(l2.left) == t
78 &&
79 right.isEqual(l2.right) == t )
80 return
81 t;
82 }
83
84 return
85 nil;
86 }
87
88
89
90
91
92
93 public
94 String toString() {
95 return
96 "( " + left.toString() + " . " + right.toString() + " )";
97 }
98}
99