@@ -7,6 +7,7 @@ use crate::persistent_list::{PersistentList, ToPersistentList, ToPersistentListI
77use crate :: persistent_list_map:: { PersistentListMap , ToPersistentListMapIter } ;
88use crate :: persistent_vector:: PersistentVector ;
99use crate :: symbol:: Symbol ;
10+ use crate :: keyword:: Keyword ;
1011use crate :: type_tag:: TypeTag ;
1112
1213extern crate rand;
@@ -28,6 +29,7 @@ use std::rc::Rc;
2829pub enum Value {
2930 I32 ( i32 ) ,
3031 Symbol ( Symbol ) ,
32+ Keyword ( Keyword ) ,
3133 IFn ( Rc < dyn IFn > ) ,
3234 //
3335 // Special case functions
@@ -77,6 +79,12 @@ impl PartialEq for Value {
7779 return sym == sym2;
7880 }
7981 }
82+
83+ if let Keyword ( kw) = self {
84+ if let Keyword ( kw2) = other {
85+ return kw == kw2;
86+ }
87+ }
8088 // Equality not defined on functions, similar to Clojure
8189 // Change this perhaps? Diverge?
8290 if let IFn ( _) = self {
@@ -173,6 +181,7 @@ impl Hash for Value {
173181 match self {
174182 I32 ( i) => i. hash ( state) ,
175183 Symbol ( sym) => sym. hash ( state) ,
184+ Keyword ( kw) => kw. hash ( state) ,
176185 IFn ( _) => {
177186 let mut rng = rand:: thread_rng ( ) ;
178187 let n2: u16 = rng. gen ( ) ;
@@ -208,6 +217,7 @@ impl fmt::Display for Value {
208217 let str = match self {
209218 I32 ( val) => val. to_string ( ) ,
210219 Symbol ( sym) => sym. to_string ( ) ,
220+ Keyword ( kw) => kw. to_string ( ) ,
211221 IFn ( _) => std:: string:: String :: from ( "#function[]" ) ,
212222 LexicalEvalFn => std:: string:: String :: from ( "#function[lexical-eval*]" ) ,
213223 PersistentList ( plist) => plist. to_string ( ) ,
@@ -245,6 +255,7 @@ impl Value {
245255 match self {
246256 Value :: I32 ( _) => TypeTag :: I32 ,
247257 Value :: Symbol ( _) => TypeTag :: Symbol ,
258+ Value :: Keyword ( _) => TypeTag :: Keyword ,
248259 Value :: IFn ( _) => TypeTag :: IFn ,
249260 Value :: LexicalEvalFn => TypeTag :: IFn ,
250261 Value :: PersistentList ( _) => TypeTag :: PersistentList ,
@@ -594,6 +605,11 @@ impl ToValue for Symbol {
594605 Value :: Symbol ( self . clone ( ) )
595606 }
596607}
608+ impl ToValue for Keyword {
609+ fn to_value ( & self ) -> Value {
610+ Value :: Keyword ( self . clone ( ) )
611+ }
612+ }
597613impl ToValue for Rc < dyn IFn > {
598614 fn to_value ( & self ) -> Value {
599615 Value :: IFn ( Rc :: clone ( self ) )
0 commit comments