@@ 3,7 3,7 @@ mod matching;
use std::{
borrow::Cow,
cmp::{max, min},
- str,
+ fmt, str,
};
const SYMBOL_CHARS: &str = "\0abcdefghijklmnopqrstuvxyz+-*?0123456789";
@@ 245,6 245,33 @@ impl PartialEq<i64> for Lisp {
}
}
+impl fmt::Display for Lisp {
+ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ match self {
+ Lisp::Int(x) => x.fmt(f),
+ Lisp::Float(x) => x.fmt(f),
+ Lisp::Symbol(x) => x.fmt(f),
+ Lisp::String(x) => fmt::Debug::fmt(x, f),
+ Lisp::List(xs) => {
+ write!(f, "(")?;
+ if let Some((xn, xs)) = xs.split_last() {
+ for x in xs {
+ write!(f, "{x} ")?
+ }
+ write!(f, "{xn}")?
+ }
+ write!(f, ")")
+ }
+ }
+ }
+}
+
+impl fmt::Display for Symbol {
+ fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ self.unpack_str().fmt(f)
+ }
+}
+
#[cfg(test)]
mod test {
use super::*;