From 3bb825fa589143649f239fc6f3f68a2b662c567b Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 17 Oct 2023 15:31:43 -0400 Subject: [PATCH] Improve for loop implementation --- examples/for_loop.ds | 3 +++ src/abstract_tree/for.rs | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/for_loop.ds b/examples/for_loop.ds index 67d368e..453a296 100644 --- a/examples/for_loop.ds +++ b/examples/for_loop.ds @@ -1,3 +1,6 @@ +i = 0 for i in [1 2 3] { + i += 1 (output i) } +(output i) diff --git a/src/abstract_tree/for.rs b/src/abstract_tree/for.rs index 3d51798..3df4ee2 100644 --- a/src/abstract_tree/for.rs +++ b/src/abstract_tree/for.rs @@ -31,15 +31,14 @@ impl AbstractTree for For { let value = self.expression.run(source, context)?; let list = value.as_list()?; let key = self.identifier.inner(); + let mut context = context.clone(); for value in list { context.set_value(key.clone(), value.clone())?; - self.item.run(source, context)?; + self.item.run(source, &mut context)?; } - context.set_value(key.clone(), Value::Empty)?; - Ok(Value::Empty) } }