I don't see anything super obviously wrong, but I only just read through it. 
Your test suite looks like it could maybe use a mixture of inserts & deletes in 
either order while iterating, but @e / @spip / @GordonBGood / @rayman22201 
should probably take a look.

It may not be so appropriate to your "tree structure surgery while iterating" 
use case, but I happened to do Yet Another Idea just the other day over at 
[https://forum.nim-lang.org/t/5506](https://forum.nim-lang.org/t/5506) which 
bypasses the Nim iterator syntax framework for a Nim template that accepts 
multiple body clauses. So, `for path in itr(params): perElement` becomes: 
    
    
    forPath(params): cannotRecurseWork
    do: perElementWork
    do: preRecurseWork
    do: postRecurseWork
    
    
    Run

Internally, that `template forPath` is just a regular recursive function that 
exposes these "hooks" for the clauses. The end of that other thread has a more 
complete example of using that `forPath` defined in 
`https://github.com/c-blake/cligen/` in the `cligen/dents.nim` submodule. 
Something like XML would not need to worry about file system permission issues 
and that first clause.

It is not very easy to use/safe, but it is yet another way to package up 
walking trees without recursive iterators that "looks similar" to Nim iterators 
that a reader of this thread may care to be aware of.

Reply via email to