lua-users home
lua-l archive

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


On Sun, Dec 05, 2010 at 12:09:34PM +0200, Lorenzo Donati wrote:
> Dirk Laurie wrote:
> > I agree that there are many applications in which the cardinality
> > of a table is a necessary concept, but please don't change the meaning
> > of the hash.  Backward-incompatible changes that cause existing 
> > programs to break are only allowable if truly unavoidable.  Better 
> > have a function with a another name (table.size?) for the actual
> > number of objects in a table.
> > 
> 
> Yes, definitely. I wouldn't welcome such a change of semantics, 
> especially because it wouldn't fit all use cases.
> As for naming, table.size would still be a bit unclear. I would prefer 
> something more explicit still (say, table.nofentries or 
> table.nofkvpairs, notwithstanding their ugliness, or something alike).
> 
Well, if one must be pedantic, table.cardinality is precise.  
But I'm happy with table.size.  Humpty Dumpty...

It's quite enlightening to compare mechanisms to access some 
sort of table size over the last three versions of Lua.

5.0 has n, getn() and setn().
5.1 has maxn() and the # operator.
5.2 has only the # operator.

None of these is precisely "the number of non-null values",
even though that number can be provided with complexity O(1).
What will 5.3 bring? 

Dirk