TSa Thomas.Sandlass-at-vts-systems.de |Perl 6| wrote:
Since Larry said that single assignment semantics is the ideal
we should strive for, I would opt for the iterator being unaffected
by the assignment to @a. When this happens the singly assigned
former content of @a is snaphot by the iterator.

That's what my C++ vararray class does with iterators. That way they don't go stale if you manipulate the array during iteration.

Iterators are independent objects in Perl 6 that can be used in other ways. I think it vaguly specifies in the synopses that the for loop will use the default iterator for that List, provided by a member for that purpose.

You can have different iterator types that work in different ways. You can create which ever kind you need for the purpose.

The synopses does not specify the details of iterators. But you can logically deduce that the default iterator needs to provide for rw (not ref?) binding, since the for loop is documented to do that, if the for loop uses the default iterator. The meta-law is that things work like in Perl 5 unless specified otherwise, so the for loop needs to continue to track the changing contents of the List object.

But I imagine you can create an iterator with various options: snapshot or tracking, rw, readonly, or ref, and other attributes.

So if you really wanted to depend on those semantics, you could write something like

   my $it = @a.iterator(:snapshot);
   while =$it -> { body-of-loop }

You could allow adverbs on the 'for' loop to pass through to the call to iterator(), but that is probably too much syntactic sugar for the value it gives.


Reply via email to