diff --git a/src/value.rs b/src/value.rs index a8d2d62..e280472 100644 --- a/src/value.rs +++ b/src/value.rs @@ -12,11 +12,10 @@ pub enum Value<'a> { List(Box>), Vector(Vec), Map(BTreeMap), - Symbol(Cow<'a, str>), + Symbol(Symbol<'a>), Keyword(Cow<'a, str>), Function { - args: Vec>, - body: Box>, + // TODO: Fields, }, Bool(bool), Number(OrderedFloat), @@ -24,6 +23,27 @@ pub enum Value<'a> { Nil, } +#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub enum Symbol<'a> { + Interned(u64), + String(Cow<'a, str>), +} + +impl<'a> From<&'a str> for Symbol<'a> { + fn from(s: &'a str) -> Self { + Self::String(Cow::Borrowed(s)) + } +} + +impl<'a> Display for Symbol<'a> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Symbol::Interned(n) => write!(f, "#{n}"), + Symbol::String(s) => write!(f, "{s}"), + } + } +} + impl<'a> Display for Value<'a> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self {