lua-users home
lua-l archive

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


On 2012-12-05 4:11 AM, "spir" <denis.spir@gmail.com> wrote:
>
> On 04/12/2012 22:28, Dirk Laurie wrote:
>>
>> 2012/12/4 spir <denis.spir@gmail.com>:
>>
>>
>>> PS: The more I think at it, the more imposes itself the idea
>>> we need 2 nils: one "nullnil" for required data, meaning a real
>>> error, "too bad, missing, try again another day"; one "nonenil"
>>> for optional data, thus just meaning "not there!".
>>
>>
>> The distinction between "none" and "nil" is available in the C API, with
>> explicit equivalence only on request (lua_isnil, lua_isnone, lua_isnoneornil).
>> In Lua itself, the idiom for customized missing data is a dedicated
>> identifier, e.g.
>>
>>      none = {}
>>
>> Do you have an application in mind where you are in Lua all the time
>> and where the "none" idiom would not be sufficient?
>
>
> no. Indeed, you are right, the solution you give is precisely the one I use when the distinction is _absolutely_ needed (because of semantic or practicle confusion).
> yes. Because "none-nil" does not exist in the language, noone ever makes the distinction, or nearly. And we get the confusion as well as real errors and sometimes difficult bugs.
>
> I mean, in practice, the problems exist (I don't invent them, they're documented even in C++ with abuse of NULL for app-semantic meaning). And the distinction between required data and optional data also is real.
>
> Denis
>
>

I suppose you can have a "none" object in C, too:
const void* none = "some unique string that will never occur in the source";

That would be analogous to "none = {}" in Lua.