From fa8d46e3d75a4403219e315982391a99d840bc0e Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 29 Dec 2017 05:10:03 -0800 Subject: [PATCH] Print operation --- src/rukka_lang/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/rukka_lang/mod.rs b/src/rukka_lang/mod.rs index 7c647bc..ad4b7a1 100644 --- a/src/rukka_lang/mod.rs +++ b/src/rukka_lang/mod.rs @@ -23,6 +23,7 @@ impl EvaluatorState { default_map.insert(format!("<"), Primitive(Less)); default_map.insert(format!("<="), Primitive(LessThanOrEqual)); default_map.insert(format!(">="), Primitive(GreaterThanOrEqual)); + default_map.insert(format!("display"), Primitive(Display)); EvaluatorState { binding_stack: vec![default_map], @@ -282,7 +283,7 @@ enum Sexp { #[derive(Debug, PartialEq, Clone)] enum PrimitiveFn { - Plus, Minus, Mult, Div, Mod, Greater, Less, GreaterThanOrEqual, LessThanOrEqual + Plus, Minus, Mult, Div, Mod, Greater, Less, GreaterThanOrEqual, LessThanOrEqual, Display } impl PrimitiveFn { @@ -291,6 +292,12 @@ impl PrimitiveFn { use self::PrimitiveFn::*; let op = self.clone(); Ok(match op { + Display => { + for arg in evaled_operands { + print!("{}\n", arg.print()); + } + Nil + }, Plus | Mult => { let mut result = match op { Plus => 0, Mult => 1, _ => unreachable!() }; for arg in evaled_operands {