Print operation

This commit is contained in:
greg 2017-12-29 05:10:03 -08:00
parent 4598802999
commit fa8d46e3d7

View File

@ -23,6 +23,7 @@ impl EvaluatorState {
default_map.insert(format!("<"), Primitive(Less)); default_map.insert(format!("<"), Primitive(Less));
default_map.insert(format!("<="), Primitive(LessThanOrEqual)); default_map.insert(format!("<="), Primitive(LessThanOrEqual));
default_map.insert(format!(">="), Primitive(GreaterThanOrEqual)); default_map.insert(format!(">="), Primitive(GreaterThanOrEqual));
default_map.insert(format!("display"), Primitive(Display));
EvaluatorState { EvaluatorState {
binding_stack: vec![default_map], binding_stack: vec![default_map],
@ -282,7 +283,7 @@ enum Sexp {
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
enum PrimitiveFn { enum PrimitiveFn {
Plus, Minus, Mult, Div, Mod, Greater, Less, GreaterThanOrEqual, LessThanOrEqual Plus, Minus, Mult, Div, Mod, Greater, Less, GreaterThanOrEqual, LessThanOrEqual, Display
} }
impl PrimitiveFn { impl PrimitiveFn {
@ -291,6 +292,12 @@ impl PrimitiveFn {
use self::PrimitiveFn::*; use self::PrimitiveFn::*;
let op = self.clone(); let op = self.clone();
Ok(match op { Ok(match op {
Display => {
for arg in evaled_operands {
print!("{}\n", arg.print());
}
Nil
},
Plus | Mult => { Plus | Mult => {
let mut result = match op { Plus => 0, Mult => 1, _ => unreachable!() }; let mut result = match op { Plus => 0, Mult => 1, _ => unreachable!() };
for arg in evaled_operands { for arg in evaled_operands {