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 {
|
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))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
; This is a comment
|
; This is a comment
|
||||||
|
|
||||||
(print
|
(print "Hello, world!")
|
||||||
(add 0.5 3)
|
|
||||||
|
(print (1 2 3))
|
||||||
|
|
||||||
|
(print
|
||||||
|
(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)
|
|
||||||
; })
|
|
||||||
; })
|
|
||||||
|
|
Reference in a new issue