Make for loops for efficient.

This commit is contained in:
Stephen Chung
2021-12-31 15:59:13 +08:00
parent 97900320e1
commit e3aa2c19ce
3 changed files with 85 additions and 18 deletions

View File

@@ -371,3 +371,31 @@ fn test_for_module_iterator() -> Result<(), Box<EvalAltResult>> {
Ok(())
}
#[test]
#[cfg(not(feature = "no_closure"))]
fn test_for_capture() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
assert_eq!(
engine.eval::<INT>(
"
let a = [];
for (x, i) in 100..110 {
a += || i + x;
}
let sum = 0;
for fp in a {
sum += fp.call();
}
sum
"
)?,
1180
);
Ok(())
}