[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How can one decide between 'not set' and 'not existing?
- From: Josh Simmons <simmons.44@...>
- Date: Tue, 24 Jul 2012 13:03:40 +1000
On Tue, Jul 24, 2012 at 12:50 PM, <meino.cramer@gmx.de> wrote:
> Hi,
>
> Suppose one do
>
> a = { key = nil }
> print( a.key )
>
> => nil
>
> print( a.carkey )
>
> => nil
>
> It looks like setting a key in a hash with value nil is the
> same as if the key does not exist at all.
>
> How can I decide between both in a program?
> Is there a 'exists' function as in Perl?
>
> Best regards and thank you very much in advance for any help!
> mcc
>
>
>
>
You cannot make such a distinction. Setting a table value to nil is
how one removes a key-value pair from the table.
In the case that a distinction is absolutely necessary (sometimes is
required when interoperating with other formats which have an explicit
null like json), a unique sentinel value is often used to represent a
key that exists with null value. e.g. local null = {} table.key = null