1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

fix: better list & vector fmt

This commit is contained in:
Natapat Samutpong 2022-01-22 06:53:56 +07:00
parent af2299e78f
commit c03ec9e5f4
2 changed files with 6 additions and 16 deletions

View file

@ -23,7 +23,9 @@ fn main() {
// Everything is in a List(..) so we need to get it out and make it into
// a vector of Expr instead, so we can compile it.
let a = util::unwrap_list_nest(ast.unwrap());
println!("{:#?}", a);
for e in a.iter() {
println!("{}", e);
}
// TODO: compile to something else..
}
}

View file

@ -20,22 +20,10 @@ impl std::fmt::Display for Expr {
Expr::Null => write!(f, "Null"),
Expr::Bool(b) => write!(f, "{}", b),
Expr::Number(n) => write!(f, "{}", n),
Expr::String(s) => write!(f, "{}", unescape(s.to_string())),
Expr::String(s) => write!(f, "\"{}\"", unescape(s.to_string())),
Expr::Symbol(s) => write!(f, "{}", s),
Expr::List(l, _) => {
write!(f, "(")?;
for e in l.iter() {
write!(f, "{}", e)?;
}
write!(f, ")")
}
Expr::Vector(l, _) => {
write!(f, "[")?;
for e in l.iter() {
write!(f, "{}", e)?;
}
write!(f, "]")
}
Expr::List(l, _) => write!(f, "({})", l.iter().map(|e| format!("{}", e)).collect::<Vec<String>>().join(" ")),
Expr::Vector(l, _) => write!(f, "[{}]", l.iter().map(|e| format!("{}", e)).collect::<Vec<String>>().join(", ")),
}
}
}