1
0

Improve for loop implementation

This commit is contained in:
Jeff 2023-10-17 15:31:43 -04:00
parent 173e7a2ee8
commit 3bb825fa58
2 changed files with 5 additions and 3 deletions

View File

@ -1,3 +1,6 @@
i = 0
for i in [1 2 3] { for i in [1 2 3] {
i += 1
(output i) (output i)
} }
(output i)

View File

@ -31,15 +31,14 @@ impl AbstractTree for For {
let value = self.expression.run(source, context)?; let value = self.expression.run(source, context)?;
let list = value.as_list()?; let list = value.as_list()?;
let key = self.identifier.inner(); let key = self.identifier.inner();
let mut context = context.clone();
for value in list { for value in list {
context.set_value(key.clone(), value.clone())?; 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) Ok(Value::Empty)
} }
} }