Redefined symbol
This commit is contained in:
parent
107a81fa55
commit
178e790d84
26
src/value.rs
26
src/value.rs
|
@ -12,11 +12,10 @@ pub enum Value<'a> {
|
||||||
List(Box<List<'a>>),
|
List(Box<List<'a>>),
|
||||||
Vector(Vec<Self>),
|
Vector(Vec<Self>),
|
||||||
Map(BTreeMap<Self, Self>),
|
Map(BTreeMap<Self, Self>),
|
||||||
Symbol(Cow<'a, str>),
|
Symbol(Symbol<'a>),
|
||||||
Keyword(Cow<'a, str>),
|
Keyword(Cow<'a, str>),
|
||||||
Function {
|
Function {
|
||||||
args: Vec<Value<'a>>,
|
// TODO: Fields,
|
||||||
body: Box<Value<'a>>,
|
|
||||||
},
|
},
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
Number(OrderedFloat<f64>),
|
Number(OrderedFloat<f64>),
|
||||||
|
@ -24,6 +23,27 @@ pub enum Value<'a> {
|
||||||
Nil,
|
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> {
|
impl<'a> Display for Value<'a> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Reference in a new issue