Delete some unneeded code

This commit is contained in:
greg 2017-12-29 04:55:03 -08:00
parent 23c0f54042
commit 5ea83e2da6

View File

@ -92,18 +92,12 @@ impl EvaluatorState {
fn eval(&mut self, expr: Sexp) -> Result<Sexp, String> { fn eval(&mut self, expr: Sexp) -> Result<Sexp, String> {
use self::Sexp::*; use self::Sexp::*;
Ok(match expr { Ok(match expr {
SymbolAtom(ref sym) => { SymbolAtom(ref sym) => match self.get_var(sym) {
if let Some(op) = get_builtin(sym) { Some(ref sexp) => {
Primitive(op) let q: &Sexp = sexp; //WTF? if I delete this line, the copy doesn't work??
} else { q.clone() //TODO make this not involve a clone
match self.get_var(sym) { },
Some(ref sexp) => { None => return Err(format!("Variable {} not bound", sym)),
let q: &Sexp = sexp; //WTF? if I delete this line, the copy doesn't work??
q.clone() //TODO make this not involve a clone
},
None => return Err(format!("Variable {} not bound", sym)),
}
}
}, },
expr @ Primitive(_) => expr, expr @ Primitive(_) => expr,
expr @ FnLiteral { .. } => expr, expr @ FnLiteral { .. } => expr,
@ -313,15 +307,6 @@ enum PrimitiveFn {
Plus, Minus, Mult, Div, Mod, Greater, Less, GreaterThanOrEqual, LessThanOrEqual Plus, Minus, Mult, Div, Mod, Greater, Less, GreaterThanOrEqual, LessThanOrEqual
} }
fn get_builtin(sym: &String) -> Option<PrimitiveFn> {
use self::PrimitiveFn::*;
Some(match &sym[..] {
"+" => Plus, "-" => Minus, "*" => Mult, "/" => Div, "%" => Mod,
">" => Greater, "<" => Less, ">=" => GreaterThanOrEqual, "<=" => LessThanOrEqual,
_ => return None
})
}
impl Sexp { impl Sexp {
fn print(&self) -> String { fn print(&self) -> String {
use self::Sexp::*; use self::Sexp::*;