Implementing new types

- nil symbols
- Bool
- Vectors
- Maps
This commit is contained in:
teo3300
2023-06-06 16:33:01 +02:00
parent 13790d0864
commit 703b6888b5
4 changed files with 64 additions and 33 deletions

View File

@ -2,8 +2,10 @@ use crate::types::MalType;
pub fn pr_str(ast: &MalType) -> String {
match ast {
MalType::Nil => "nil".to_string(),
MalType::Symbol(sym) => sym.to_string(),
MalType::Integer(val) => val.to_string(),
MalType::Bool(val) => val.to_string(),
MalType::List(el) => format!(
"({})",
el.iter()
@ -11,5 +13,20 @@ pub fn pr_str(ast: &MalType) -> String {
.collect::<Vec<String>>()
.join(" ")
),
// This is truly horrible
MalType::Vector(el) => format!(
"[{}]",
el.iter()
.map(|sub| pr_str(sub))
.collect::<Vec<String>>()
.join(" ")
),
MalType::Map(el) => format!(
"{{{}}}",
el.iter()
.map(|sub| vec![pr_str(sub.0), pr_str(sub.1)].join(" "))
.collect::<Vec<String>>()
.join(" ")
),
}
}