Redefined symbol

main
ondra05 2022-07-21 13:22:25 +02:00
parent 7306465455
commit b4cd0fba1d
1 changed files with 23 additions and 3 deletions

View File

@ -12,11 +12,10 @@ pub enum Value<'a> {
List(Box<List<'a>>),
Vector(Vec<Self>),
Map(BTreeMap<Self, Self>),
Symbol(Cow<'a, str>),
Symbol(Symbol<'a>),
Keyword(Cow<'a, str>),
Function {
args: Vec<Value<'a>>,
body: Box<Value<'a>>,
// TODO: Fields,
},
Bool(bool),
Number(OrderedFloat<f64>),
@ -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 {