From f33cfdadfef34c61cd72157c0828a5dca6b1598e Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 25 Jan 2016 01:36:59 -0800 Subject: [PATCH] Fix variable lookup order Evaluator uses frames as a stack, so to find the most-recent variable binding we have to iterate through it the reverse way. This fixes a bug manifested by: fn a(x) x + 20 end fn b(x) a(x) + 20 end --- src/eval.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eval.rs b/src/eval.rs index 9490676..73bb9b4 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -51,7 +51,7 @@ impl Evaluator { } fn lookup_binding(&mut self, var: String) -> Option { - for frame in self.frames.iter() { + for frame in self.frames.iter().rev() { match frame.map.get(&var) { None => (), Some(expr) => return Some(expr.clone()),