1
1
use crate :: environment:: Environment ;
2
2
use crate :: ifn:: IFn ;
3
+ use crate :: keyword:: Keyword ;
3
4
use crate :: lambda;
4
5
use crate :: maps:: MapEntry ;
5
6
use crate :: persistent_list:: PersistentList :: Cons ;
6
7
use crate :: persistent_list:: { PersistentList , ToPersistentList , ToPersistentListIter } ;
7
8
use crate :: persistent_list_map:: { PersistentListMap , ToPersistentListMapIter } ;
8
9
use crate :: persistent_vector:: PersistentVector ;
9
10
use crate :: symbol:: Symbol ;
10
- use crate :: keyword:: Keyword ;
11
11
use crate :: type_tag:: TypeTag ;
12
12
13
13
extern crate rand;
@@ -70,110 +70,29 @@ impl PartialEq for Value {
70
70
// @TODO implement our generic IFns some other way? After all, again, this isn't Java
71
71
fn eq ( & self , other : & Value ) -> bool {
72
72
//
73
- if let I32 ( i) = self {
74
- if let I32 ( i2) = other {
75
- return i == i2;
76
- }
77
- }
78
-
79
- if let F64 ( d) = self {
80
- if let F64 ( d2) = other {
81
- return d == d2;
82
- }
83
- }
84
-
85
- if let Boolean ( b) = self {
86
- if let Boolean ( b2) = other {
87
- return b == b2;
88
- }
89
- }
90
-
91
- if let Symbol ( sym) = self {
92
- if let Symbol ( sym2) = other {
93
- return sym == sym2;
94
- }
95
- }
96
-
97
- if let Keyword ( kw) = self {
98
- if let Keyword ( kw2) = other {
99
- return kw == kw2;
100
- }
101
- }
102
- // Equality not defined on functions, similar to Clojure
103
- // Change this perhaps? Diverge?
104
- if let IFn ( _) = self {
105
- if let IFn ( _) = other {
106
- return false ;
107
- }
108
- }
109
- // Is it misleading for equality to sometimes work?
110
- if let LexicalEvalFn = self {
111
- if let LexicalEvalFn = other {
112
- return true ;
113
- }
114
- }
115
-
116
- if let PersistentList ( plist) = self {
117
- if let PersistentList ( plist2) = other {
118
- return plist == plist2;
119
- }
120
- }
121
-
122
- if let PersistentVector ( pvector) = self {
123
- if let PersistentVector ( pvector2) = other {
124
- return * pvector == * pvector2;
125
- }
73
+ match ( self , other) {
74
+ ( I32 ( i) , I32 ( i2) ) => i == i2,
75
+ ( F64 ( d) , F64 ( d2) ) => d == d2,
76
+ ( Boolean ( b) , Boolean ( b2) ) => b == b2,
77
+ ( Symbol ( sym) , Symbol ( sym2) ) => sym == sym2,
78
+ ( Keyword ( kw) , Keyword ( kw2) ) => kw == kw2,
79
+ // Equality not defined on functions, similar to Clojure
80
+ // Change this perhaps? Diverge?
81
+ ( IFn ( _) , IFn ( _) ) => false ,
82
+ // Is it misleading for equality to sometimes work?
83
+ ( LexicalEvalFn , LexicalEvalFn ) => true ,
84
+ ( PersistentList ( plist) , PersistentList ( plist2) ) => plist == plist2,
85
+ ( PersistentVector ( pvector) , PersistentVector ( pvector2) ) => * pvector == * pvector2,
86
+ ( PersistentListMap ( plistmap) , PersistentListMap ( plistmap2) ) => * plistmap == * plistmap2,
87
+ ( Condition ( msg) , Condition ( msg2) ) => msg == msg2,
88
+ ( QuoteMacro , QuoteMacro ) => true ,
89
+ ( DefmacroMacro , DefmacroMacro ) => true ,
90
+ ( DefMacro , DefMacro ) => true ,
91
+ ( LetMacro , LetMacro ) => true ,
92
+ ( String ( string) , String ( string2) ) => string == string2,
93
+ ( Nil , Nil ) => true ,
94
+ _ => false ,
126
95
}
127
-
128
- if let PersistentListMap ( plistmap) = self {
129
- if let PersistentListMap ( plistmap2) = other {
130
- return * plistmap == * plistmap2;
131
- }
132
- }
133
-
134
- if let Condition ( msg) = self {
135
- if let Condition ( msg2) = other {
136
- return msg == msg2;
137
- }
138
- }
139
-
140
- if let QuoteMacro = self {
141
- if let QuoteMacro = other {
142
- return true ;
143
- }
144
- }
145
-
146
- if let DefmacroMacro = self {
147
- if let DefmacroMacro = other {
148
- return true ;
149
- }
150
- }
151
-
152
- if let DefMacro = self {
153
- if let DefMacro = other {
154
- return true ;
155
- }
156
- }
157
-
158
- if let LetMacro = self {
159
- if let LetMacro = other {
160
- return true ;
161
- }
162
- }
163
-
164
- if let String ( string) = self {
165
- if let String ( string2) = other {
166
- return string == string2;
167
- }
168
- }
169
-
170
- if let Nil = self {
171
- if let Nil = other {
172
- return true ;
173
- }
174
- }
175
-
176
- false
177
96
}
178
97
}
179
98
@@ -197,7 +116,7 @@ impl Hash for Value {
197
116
F64 ( d) => d. to_value ( ) . hash ( state) ,
198
117
Boolean ( b) => b. hash ( state) ,
199
118
Symbol ( sym) => sym. hash ( state) ,
200
- Keyword ( kw) => kw. hash ( state) ,
119
+ Keyword ( kw) => kw. hash ( state) ,
201
120
IFn ( _) => {
202
121
let mut rng = rand:: thread_rng ( ) ;
203
122
let n2: u16 = rng. gen ( ) ;
@@ -235,7 +154,7 @@ impl fmt::Display for Value {
235
154
F64 ( val) => val. to_string ( ) ,
236
155
Boolean ( val) => val. to_string ( ) ,
237
156
Symbol ( sym) => sym. to_string ( ) ,
238
- Keyword ( kw) => kw. to_string ( ) ,
157
+ Keyword ( kw) => kw. to_string ( ) ,
239
158
IFn ( _) => std:: string:: String :: from ( "#function[]" ) ,
240
159
LexicalEvalFn => std:: string:: String :: from ( "#function[lexical-eval*]" ) ,
241
160
PersistentList ( plist) => plist. to_string ( ) ,
@@ -275,7 +194,7 @@ impl Value {
275
194
Value :: F64 ( _) => TypeTag :: F64 ,
276
195
Value :: Boolean ( _) => TypeTag :: Boolean ,
277
196
Value :: Symbol ( _) => TypeTag :: Symbol ,
278
- Value :: Keyword ( _) => TypeTag :: Keyword ,
197
+ Value :: Keyword ( _) => TypeTag :: Keyword ,
279
198
Value :: IFn ( _) => TypeTag :: IFn ,
280
199
Value :: LexicalEvalFn => TypeTag :: IFn ,
281
200
Value :: PersistentList ( _) => TypeTag :: PersistentList ,
0 commit comments