From 5436a706d77a1666e1c7ba6d151f7d8d1cba3fcd Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Wed, 1 Jun 2022 16:35:35 -0500 Subject: [PATCH] Get/Set variables from the environment --- rust/src/evaluator.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rust/src/evaluator.rs b/rust/src/evaluator.rs index 9dcfe3c..8e670e9 100644 --- a/rust/src/evaluator.rs +++ b/rust/src/evaluator.rs @@ -31,12 +31,17 @@ impl<'a> Env<'a> { panic!("Variable {} not in scope.", id) } } + pub fn set(&mut self, id: String, atom: Atom) { + self.values.insert(id, atom); + } } pub fn eval(ast: &parser::Stmt, env: &mut Env) { match &ast { parser::Stmt::ReplPrint(expr) => println!("{}", eval_expr(expr, env)), + parser::Stmt::Assignment(id, expr) => + env.set(id.clone(), eval_expr(expr, env)), _ => todo!(), } }