lua-users home
lua-l archive

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


> My standard answer (not sure whether it is instructive) is that there is
> no good *meaning* for #t when t has holes.

Thats why, in my opinion, there should be no default answer from Lua
as well, and # should just call what __len says. The current
"capstone" should be "table.capstone" or so.

Additionally the debug interface should provide to give an default
behavior to all tables when its metatable doesn't have one. So with a
one-liner any progam you get the 5.1 behavior if you wish to like.
debug.setmetatable(table, {__len = function(t) return table.capstone(t) end})

So yes, I also don't have any good sublinear algorithm to get to a
good answer, but I suppose in most applications it is more effective
to keep track of n as separate variable either way.