[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.2 Length Operator and tables (bug?)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Tue, 17 Apr 2012 09:01:06 +0200
>
> 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.
- References:
- Lua 5.2 Length Operator and tables (bug?), csrl
- Re: Lua 5.2 Length Operator and tables (bug?), Dirk Laurie
- Re: Lua 5.2 Length Operator and tables (bug?), Jose Torre-Bueno
- Re: Lua 5.2 Length Operator and tables (bug?), Krunal Rao
- Re: Lua 5.2 Length Operator and tables (bug?), Luiz Henrique de Figueiredo
- Re: Lua 5.2 Length Operator and tables (bug?), chris
- Re: Lua 5.2 Length Operator and tables (bug?), Miles Bader
- Re: Lua 5.2 Length Operator and tables (bug?), chris
- Re: Lua 5.2 Length Operator and tables (bug?), Miles Bader
- Re: Lua 5.2 Length Operator and tables (bug?), chris