[luatex] robustness of node.traverse

Hans Hagen pragma at wxs.nl
Fri Nov 9 00:44:08 CET 2012

On 11/8/2012 10:47 PM, Stephan Hennig wrote:
> Hi,
> the manual is quite terse about node.traverse().  I'd like to know what
> operations (insertion/removal) on the node list given as argument to
> node.traverse() are save in a loop like
>    for n in node.traverse(head) do
>      ...
>    end

best is not to remove n and mess with the n.next pointer

the traverse is mostly there for fast loops that only deal with the 
properties of nodes

> I'd guess removing the current node in the loop body is not a good idea.
>   But anything else?  Sure, inserting before/after the current node
> changes the current node, too.  But that shouldn't be a problem, should it?

in that case best use

local n = head
while n do
   n = n.next

(often just as efficient)


                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl

More information about the luatex mailing list