roxen.lists.pike.general

Subject Author Date
Re: Iterators and deleting entries from mappings Martin B?hr <mbaehr[at]email[dot]archlab[dot]tuwien[dot]ac> 15-01-2009
On Thu, Jan 15, 2009 at 12:12:41PM +0100, Stephen R. van den Berg wrote:
> >so if elements are added while the mapping being iterated,
> >they might be missed, but deleting one element can't cause another
> >element to be missed. (because obviously it is present for the whole
> >iteration)
> >so it is only unclear what happens to new elements.
> >(would there be any benefit to change that?)
> This behaviour is perfect.  It is exactly what I would expect, and therefore
> there would be zero benefit to me to change that behaviour.

what is perfect about undefined behaviour?

note that this is only discussing new elements added after the iteration
started. defined behaviour would be that such elements are not interated
over (as mirar expects it), or that all of them are included in the
iteration. i don't know which is better. i sort of prefer new elements
to be ignored, but if it is an issue i can just write:

foreach(indices(m); mixed key){ use(m[key]); }

and i'd be sure that new elements will be ignored.

your deletions would never be affected by any change in behaviour
discussed here.

greetings, martin.
-- 
cooperative communication with sTeam      -     caudium, pike, roxen and unix
offering: programming, training and administration   -  anywhere in the world
--
pike programmer   working in china                      community.gotpike.org
unix system-      iaeste.(tuwien.ac|or).at                     open-steam.org
administrator     caudium.org                                    is.schon.org
Martin Bähr       http://www.iaeste.or.at/~mbaehr/