From 519fa4ee9952b4d8fe0a018f3a1cdb0167c8f5b3 Mon Sep 17 00:00:00 2001 From: Roman Godmaire Date: Sat, 17 Feb 2024 21:14:31 -0500 Subject: [PATCH] feat: display function --- src/evaluator/env.rs | 13 +++++++++++++ src/evaluator/mod.rs | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/evaluator/env.rs b/src/evaluator/env.rs index 92a76bd..f41a244 100644 --- a/src/evaluator/env.rs +++ b/src/evaluator/env.rs @@ -253,6 +253,19 @@ pub fn core_environment() -> Rc { })) }), ), + // IO + ( + "display", + Expression::NativeFunc(|args| { + if args.len() != 1 { + Err(Error::MismatchedArgCount(1, args.len()))? + } + + print!("{}", args[0]); + + Ok(Expression::Void.into()) + }), + ), ] .into_iter() .map(|(k, v)| (k.to_string(), Rc::new(v))); diff --git a/src/evaluator/mod.rs b/src/evaluator/mod.rs index 010b773..19b51d8 100644 --- a/src/evaluator/mod.rs +++ b/src/evaluator/mod.rs @@ -16,6 +16,7 @@ pub enum Expression { Keyword(String), String(String), Nil, + Void, // Collections Vector(Vec>), @@ -39,6 +40,7 @@ impl std::fmt::Display for Expression { Expression::Keyword(val) => write!(f, ":{}", val), Expression::String(val) => write!(f, "{}", val), Expression::Nil => write!(f, "()"), + Expression::Void => write!(f, ""), Expression::Vector(vec) => { let s = vec