lua-users home
lua-l archive

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


Looking at Wim's original code (which is certainly better than mine!), it
seems to me that it would actually be easier to build the iteratable table
at the beginning of the iteration. This is likely to be quite a bit faster
(in total) than building it one key at a time during the iteration; in that
case, the pairs function could simply return next, new_table, nil. Since
Wim's solution involves building a table which holds all the keys of the
combined tables anyway, in order to check them off, there is no additional
cost to putting the values into the table instead of "true".

Of course, if you were planning on quitting the iteration before it
finished, that would be a bit of wasted time.

Nonetheless, I leave it as another example of where you want to custom
"pairs" rather than "next".

Peter: your effort is well-done, but I think even after doing it you would
admit that Wim's solution is shorter and faster, and easier to write.

I am not saying that "next" is not a fundamental operation: just that next
factories are often easier to come up with than static nexts. :)

Rici