OLD | NEW |
| (Empty) |
1 part of lisp; | |
2 | |
3 /** | |
4 * The basic data structure of LISP. | |
5 */ | |
6 class Cons { | |
7 | |
8 /** The head of the cons. */ | |
9 dynamic head; | |
10 | |
11 /** The tail of the cons. */ | |
12 dynamic tail; | |
13 | |
14 /** Constructs a cons. */ | |
15 Cons(this.head, this.tail); | |
16 | |
17 @override | |
18 bool operator ==(other) { | |
19 return other is Cons && head == other.head && tail == other.tail; | |
20 } | |
21 | |
22 @override | |
23 int get hashCode => 31 * head.hashCode + tail.hashCode; | |
24 | |
25 @override | |
26 String toString() { | |
27 var buffer = new StringBuffer(); | |
28 buffer.write('('); | |
29 var current = this; | |
30 while (current is Cons) { | |
31 buffer.write(current.head.toString()); | |
32 current = current.tail; | |
33 if (current != null) { | |
34 buffer.write(' '); | |
35 } | |
36 } | |
37 if (current != null) { | |
38 buffer.write('. '); | |
39 buffer.write(current); | |
40 } | |
41 buffer.write(')'); | |
42 return buffer.toString(); | |
43 } | |
44 } | |
OLD | NEW |