c218d875 · core f63c1e69 · built 2026-10-26 22:39 UTCList<T> iteration
Limitation
List<T> now implements Iterable<T> for every T. Each for loop receives
its own copied cursor, so nested loops over the same list are independent:
fun main() {
var l: List<i64> := List::new();
l.push(1);
for (v in l) { assert(v == 1); }
}
The list's existing eager methods continue to use self.as_slice() because
they do not need iterator state.
Impact
Visible to Metel programmers: lists can now be used directly in for loops.
.as_slice() remains available when an immutable array view is specifically
required.
Affects
arch.type-inference.requirement-1metel-frontend/stdlib/core.mtl(Listand itsIterableimplementation)metel-interpreter/src/evaluator/builtins.rs(native list construction)
Resolution
Implemented for #871. The private cursor is part of the copied list value; the backing array remains the shared list storage.