lua-users home
lua-l archive

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


On 1/1/11, David J. Slate <dslate@speakeasy.net> wrote:
> When I first saw how the '#' operator applied to tables, it seemed a
> bit of an anomaly.  In a language as elegant as Lua, I expected a
> single-character core operator like '#' to have a simple, general, and
> intuitively predictable meaning when applied to the data types for
> which it's relevant.  As applied to strings it does, returning
> unambiguously the length of the string.  But applied to tables, it
> produces a sensible result only for arrays or lists with integer
> indices beginning with 1 and without "holes".  Intuitively, I would
> have expected a "length operator" as applied to an associative table
> to produce a count of its keys, regardless of what kind of table it
> was.  There could of course be an appropriately-named function that
> worked like '#' actually does.

+1

Yes, a count of keys would be reasonable, O(1), and if one had been
careful with his tables, would accidentally coincide with #'s current
semantics