lua-users home
lua-l archive

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


2013/6/28 Tim Hill <drtimhill@gmail.com>:

> I'm going to get shot for suggesting this… (hides under bed)

No, you won't. We've all been through this phase and survived it.

> I think there IS a case to be made for being able to store
> a value in a Lua array that is uniquely NOT any other Lua value.
> Essentially, I think that value is "empty"; a valid Lua value
> that is simply not the same as any other Lua value (including nil).
>
> Basically, empty would act like nil in most regards, except:
> -- Storing empty in a table element actually stores the value,
>    rather than deletes it.
> -- When used in a boolean context, the empty value evaluates
>    to true (unlike nil).
> -- Has a type() of "empty"

Would `empty` be allowed as a table key?

> -- Judging by the mail list chatter, a lot of Lua beginners
>    struggle with the problem of nil in sequences.

It would be so much nicer to have them struggle with `empty`
instead.

> But, let's face it; they ARE all workarounds.

Those workarounds are not workarounds, they are special-purpose
solutions to special-purpose problems.

Here's another "workaround":

   NaN = 0/0

It's different from all Lua values, including `nil` _and itself_.
It occupies a TValue, but is not a valid table key.

The proposed `empty` is likewise a mere workaround. Another
special-purpose solution to another special-purpose problem.