MantisBT - Documentation, Examples, and Web Site
View Issue Details
0001208Documentation, Examples, and Web SiteWriting with Informpublic2014-03-21 02:522014-05-07 07:38
curiousdannii 
graham 
normalmildN/A
closedfixed 
6G60 
6L02 
0001208: Repeat with precomputes the next iteration's value and is sometimes unsafe
This is filed as a documentation issue because we figure you have good reasons for implementing it as you have, though if that's not the case please consider changing the implementation too!

So in Kerkerkruip we've run into a nasty bug which was very hard to diagnose: https://github.com/i7/kerkerkruip/issues/258#issuecomment-38198215 [^]

The core of the problem is that repeat with loops precompute the next iteration's value. This causes problems if the code for the current iteration alters the next object so that it no longer qualifies.

The docs should be updated to make authors aware of this potential problem, and to suggest how to safely perform these loops. "while there is (description) (called H):" is a safe alternative.
No tags attached.
Issue History
2014-03-21 02:52curiousdanniiNew Issue
2014-03-21 10:05zarfNote Added: 0002582
2014-03-21 15:14curiousdanniiNote Added: 0002583
2014-03-27 14:27EmacsUserReproducibilityhave not tried => N/A
2014-03-27 14:27EmacsUserStatusnew => confirmed
2014-04-15 20:16curiousdanniiSummaryRepeat with precomputes the next iteration's value and is unsafe => Repeat with precomputes the next iteration's value and is sometimes unsafe
2014-04-15 20:16curiousdanniiDescription Updatedbug_revision_view_page.php?rev_id=994#r994
2014-04-21 14:20grahamNote Added: 0002632
2014-04-21 14:20grahamStatusconfirmed => resolved
2014-04-21 14:20grahamResolutionopen => fixed
2014-04-21 14:20grahamAssigned To => graham
2014-05-07 07:37jmcgrewFixed in Version => 6L02
2014-05-07 07:38jmcgrewStatusresolved => closed

Notes
(0002582)
zarf   
2014-03-21 10:05   
The precomputation supports the (presumed common) case:

repeat with T running through things in the pot: now T is off-stage;

...which uses a linked-list and would therefore choke without precomputation.

(Sure, *I* would use a "now all things in the pot..." statement here, but not everyone would.)

I feel like precomputation is going to give the desired result in "most" cases. I haven't done any systematic study, but I figure that the ideal behavior is to decide the entire iterator set in advance and then loop through it. This is impractical for memory reasons, but precompute-one is a step closer to it than naive iteration.

I took a look at the Kerkerkruip bug but I'm not sure what the loop structure is.
(0002583)
curiousdannii   
2014-03-21 15:14   
Hmm I guess the underlying issue is that the iteration functions require the object to still match the description in order to find the next one. I don't really know how those functions work, but I wonder if they couldn't just store an index instead?

Kerkerkruip loops through windows opening them one at a time. But some of the windows then open windows themselves. When it gets back to the original loop it already has the next iteration's window and opens it even though it's already open.
(0002632)
graham   
2014-04-21 14:20   
I've added a note to the documentation.