Update value formatting

This commit is contained in:
Apache 2024-06-20 19:38:09 -05:00
parent 9507ff65a3
commit 6de96afccf
Signed by: apache
GPG key ID: 6B10F3EAF14F4C77
2 changed files with 25 additions and 13 deletions

View file

@ -25,11 +25,24 @@ impl fmt::Display for LispValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
LispValue::Nil => write!(f, "nil"), LispValue::Nil => write!(f, "nil"),
LispValue::String(str) => write!(f, "{}", str), LispValue::String(str) => write!(f, "\"{}\"", str),
LispValue::LispFunction(name, _) => write!(f, "<'{}': Lisp Function>", name), LispValue::LispFunction(name, _) => write!(f, "<function {}>", name),
LispValue::RustFunction(name, _) => write!(f, "<'{}': Rust Function>", name), LispValue::RustFunction(name, _) => write!(f, "<function {}>", name),
LispValue::Integer(num) => write!(f, "{}", num), LispValue::Integer(num) => write!(f, "{}", num),
LispValue::Float(num) => write!(f, "{}", num), LispValue::Float(num) => write!(f, "{}", num),
LispValue::List(elems, quoted) => {
let mut strs = Vec::new();
for e in elems {
strs.push(e.to_string());
}
if *quoted {
write!(f, "'({})", strs.join(", "))
} else {
write!(f, "({})", strs.join(", "))
}
},
val => { val => {
write!(f, "{}", format!("{:?}", val)) write!(f, "{}", format!("{:?}", val))
} }

View file

@ -1,14 +1,13 @@
; This is a comment ; This is a comment
(print "Hello, world!")
(print (1 2 3))
(print (print
(add 0.5 3) (add 15 105.3)
) )
; LispValue::List({ (print
; LispValue::RustFunction("print", <rust fn type>), '(add 15 105.3)
; LispValue::List({ )
; LispValue::RustFunction("add", <rust fn type>),
; LispValue::Float(1.0),
; LispValue::Integer(3)
; })
; })