lua-users home
lua-l archive

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


The thread has been hijacked, but this OP enjoys the direction
in which it is running.

2016-06-28 5:29 GMT+02:00 Tim Hill <drtimhill@gmail.com>:
>
> To be honest I’ve never liked the use of “n” as a pseudo-length.
>  First, it’s inconsistent (collides with use of #). Second, it’s hi-jacking
> a perfectly normal user key with very little notice (why wasn’t a reserved
> “_N” used?).

Why must such a key match "[_%a]%w*"? Can't we reserve tbl["#"]
for the purpose? With the semantics of "__len" extended to treat
that as a first fallback? I.e.

1. If the __index metamethod exists, use it.
2. If not, use tbl["#"] as the length.
3. If that is nil or false, revert to the built-in algorithm.

> My personal feeling is that we need a first-class explicitly set length.

["#"] is less convenient that .n or ._N, sure, but do we want it to
be convenient? When debugging, something as drastic as
redefining the length of a table should be obtrusively visible.