lua-users home
lua-l archive

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


>
> Following the train of thought, I'd suggest that the length operator always
> return nil unless a __len metamethod exists.  For people working with sequences
> it becomes trivial to wrap the proposed table.len() function inside that meta
> method.  Now it becomes explicit that the table creator knows the table is a
> sequence.
>

| The trouble with folk is not the things they don't know, but the
| things they know that ain't so. — Josh Billings

An inferred principle of Lua design is: protect idiots against themselves,
but not at the cost of performance.  Testing whether a table is a sequence is
very expensive.  Forcing innocent non-idiots into extra work is also out.

The 5.2 implementation of the `#`  function is still what it was for 5.1,
but for how long?  I'd say the mere use of the operator means that the
table creator "knows" (in the Billings sense) that the table is either
a sequence or properly metamethoded.