lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> for k in pairs(table) do
>   table[k] = nil
> end
>
> And, being a full iteration, it takes O(N).  The fact
> that this code snippet is correct is one of the
> 'subtleties' of 'next' (and Lua tables in general) .

This had me foxed. The manual is clear, though:

"The behavior of next is undefined if, during the traversal, you assign
any value to a *non-existent* field in the table."

(my emphasis)

-- 
http://www.mupsych.org/~rrt/ | Eschatology Generally Breeds Dire Fanaticism