lua-users home
lua-l archive

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


On Fri, Dec 03, 2010 at 02:39:30PM +0200, Roberto Ierusalimschy wrote:
> 
> The problem with # returning the actual number of elements of a table
> is not space, but that it does not solve most of the real problems that
> the current # have. It sure becomes deterministic, but mainly useless
> nonetheless. 

The current # should stay as is, although maybe it could be made
truly non-deterministic instead of deterministic but hard to explain.
For example, if an array has one hole only, at [3], the current
algorithm will never find it, but if the hole is at [4], the current
algorithm will always find it.  

Nevertheless, a function for the actual number of elements is useful 
in some applications.  Many graph-theoretical applications make use of
the number of neighbours a node has before bothering to examine those 
neighbours.  

Such a function is easy to implement cheaply by adding a few lines to 
settable_event, but it won't be so cheap if one has to do that by 
overloading __newindex at the Lua level.

Dirk