[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Strong tables in Lua 5.4
- From: Dibyendu Majumdar <mobile@...>
- Date: Wed, 21 Mar 2018 10:33:49 +0000
On Tuesday, 20 March 2018, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> On 19 March 2018 at 17:51, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> Lua 5.4 should have a constant of type nil called 'null' [1]. Not a
>> new keyword, only a new predefined value.
>>
>> All the functionality aimed for with nil-in-tables can be achieved this way.
>>
>> - Being of type nil, 'null' by itself tests false.
>> - Not being equal to nil, 'nil' is a non-hole.
>> - Can be preassigned to global values (or a value in any table) so
>> that __index can just signal an error.
>>
>
> Hi, I agree partly with your idea. Maybe Lua can have a well defined
> singleton object call MISSING or NONE or UNDEFINED. Say it is a global
> value which is actually just a Userdata.
>
> Nil should remain as is; and semantics for Nil should remain as is.
>
> Anyone wanting to put values that do not exist will simply set this to
> MISSING (If that is the global name).
>
> MISSING will evaluate to True not false as it is just another value,
> albeit a special one.
> MISSING will only be equal to another reference to MISSING and nothing else.
>
> In statistics you often have missing values. This is hard to model in
> Lua tables currently but above approach would work.
>
> Unlike others I personally do not think a break in backwards
> compatibility is at all desirable even for Lua 6.0. Introducing a
> subtype of Nil or Nil in tables has the problem that all existing Lua
> code relies upon the invariant that Nils do not appear when iterating.
>
Btw just giving credit to
Sergey Zakharchenk who originally suggested something similar.