iterating and modifying lists ----------------------------- If lists could be modified directly while being iterated over, then we could encounter bugs (and memory corruption if the current element is deleted from a linked list). As a safety measure, iterators could take ownership of the list, but implement and forward all list operations to the real list. list[item] exclusive_write^ a = ...; iterator[item] exclusive_write^ iter = a^.iterator() a = undefined; item e; while (iter.get_elem(@e)) { if (e.is_old) iter.remove_current(); if (e.previous_is_old) iter.remove_relative(-1); if (e.first_is_old) iter.remove_at(0); } a = iter.list(); iter = undefined;