From 5eba222679f9d9fcb0fcef56833b82f03174eb09 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 24 Jan 2016 15:48:56 -0800 Subject: [PATCH] Variable binding in fucntion call work --- src/eval.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/eval.rs b/src/eval.rs index 9b69ee4..bb88165 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -45,7 +45,10 @@ impl Evaluator { } fn add_binding(&mut self, var: String, value: Expression) { - self.varmap.map.insert(var, value); + match self.frames.last_mut() { + Some(frame) => frame.map.insert(var, value), + None => self.varmap.map.insert(var, value), + }; } fn lookup_binding(&mut self, var: String) -> Option { @@ -225,7 +228,10 @@ impl Evaluator { self.frames.push(frame); let mut retval = Null; for expr in function.body.iter() { - retval = self.reduce_expr(expr.clone()); + retval = expr.clone(); + while retval.is_reducible() { + retval = self.reduce_expr(retval); + } } self.frames.pop();