Update value formatting
This commit is contained in:
parent
9507ff65a3
commit
6de96afccf
2 changed files with 25 additions and 13 deletions
|
@ -25,11 +25,24 @@ impl fmt::Display for LispValue {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
LispValue::Nil => write!(f, "nil"),
|
||||
LispValue::String(str) => write!(f, "{}", str),
|
||||
LispValue::LispFunction(name, _) => write!(f, "<'{}': Lisp Function>", name),
|
||||
LispValue::RustFunction(name, _) => write!(f, "<'{}': Rust Function>", name),
|
||||
LispValue::String(str) => write!(f, "\"{}\"", str),
|
||||
LispValue::LispFunction(name, _) => write!(f, "<function {}>", name),
|
||||
LispValue::RustFunction(name, _) => write!(f, "<function {}>", name),
|
||||
LispValue::Integer(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 => {
|
||||
write!(f, "{}", format!("{:?}", val))
|
||||
}
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
; This is a comment
|
||||
|
||||
(print "Hello, world!")
|
||||
|
||||
(print (1 2 3))
|
||||
|
||||
(print
|
||||
(add 0.5 3)
|
||||
(add 15 105.3)
|
||||
)
|
||||
|
||||
; LispValue::List({
|
||||
; LispValue::RustFunction("print", <rust fn type>),
|
||||
; LispValue::List({
|
||||
; LispValue::RustFunction("add", <rust fn type>),
|
||||
; LispValue::Float(1.0),
|
||||
; LispValue::Integer(3)
|
||||
; })
|
||||
; })
|
||||
(print
|
||||
'(add 15 105.3)
|
||||
)
|
||||
|
|
Reference in a new issue