[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Strong tables in Lua 5.4
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 21 Mar 2018 08:45:16 +0200
2018-03-20 23:24 GMT+02:00 Dibyendu Majumdar <mobile@majumdar.org.uk>:
> 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.
I am not dogmatic about it. I suggested it because the current
implementation at the C level in effect has a value of _type_ nil
different from the _value_ nil. No reason why it can't be say a light
userdata instead.
Maybe the name should rather start with an underscore, since Lua
programmers have been taught not to use such names for their own
purposes.
If _EMPTY has truth value 'true', backward compatiblity would be possible:
if _EMPTY == nil then _EMPTY = function() return end end
One might argue that this would not be a new language feature at all.
Most JSON parsers that I know (e.g. 'cjson' and 'conman.json') do that
(using the name 'null'). But having _EMPTY available, and documented,
would make such subterfuges unnecessary.
Also, existing programs that accept user-written functions can, when
loaded, test for a non-nil _EMPTY and issue a warning or error.