[luatex] robustness of node.traverse
Stephan Hennig
mailing_list at arcor.de
Fri Nov 9 20:19:40 CET 2012
Am 09.11.2012 09:58, schrieb Taco Hoekwater:
> Please check the latest manual commit, I added an explanation
> of the internals of node.traverse() and node.traverse_id() that
> should make things clearer.
Thanks! To quote
| \starttyping
| for n in node.traverse(head) do
| ...
| end
| \stoptyping
|
| is functionally equivalent to:
|
| \starttyping
| do
| local n
| local function f (head,var)
| local t
| if var == nil then
| t = head
| else
| t = var.next
| end
| return t
| end
| while true do
| n = f (head, n)
| if n == nil then break end
| ...
| end
| end
| \stoptyping
What is the advantage of this to the naive
local n = head
while n do
...
n = n.next
end
?
Regarding traverse_id
| \starttyping
| local function f (head,var)
| local t
| if var == nil then
| t = head
| else
| t = var.next
| end
| while not t.id == id do
| t = t.next
| end
There is a guard missing in the while loop that stops when t == nil.
| return t
| end
| \stoptyping
Again, what is the advantage of this to the naive
local n = head
while n do
if n.id == <id> then
...
end
n = n.next
end
?
Best regards,
Stephan Hennig
More information about the luatex
mailing list