lua-users home
lua-l archive

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


Som quick considerations:

1) how does your routine handle GC? What happens if you delete an element
from the original table, that element is collected, and then you traverse
it (it is still in the copy)?

2) What happens if there is an error in the function called? You will not
free the "malloc" block... (I think you can fix 1 and 2 by creating a
"complete" table to keep the copy, and pushing it on the stack.)

3) We can only regret about having four different methods for order. That
was really a mistake. In fact, only one would be much better. We were
considering using only the "lt" tag method, and doing the others as
(a<=b <==> not b<a, etc). But we do not know if now it pays the
incompatibilities...

4) The problem with an equality tag method is table indexing. We always 
have that a==b => t[a] is the same element that t[b]. It would be very
confusing to break this rule, we think. And it would be very inefficient
and almost impossible to keep right if we had table indexing using a tag
method for equality. (For instance, what would happen to the old hashings
when the program redefines equality?) That is why == is hardcoded
(toghether with table indexing).

5) Lua 3.2 will have a built-in function sort, that gets a table and an 
optional "less-than" function (and does the sort in-place). A
"foreachsorted" is really a very useful function, but maybe a little
redundant with a plain sort.  We will think about that.


-- Roberto