lua-users home
lua-l archive

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


On Thu, Jul 23, 2009 at 12:03 PM, Luiz Henrique de
Figueiredo<lhf@tecgraf.puc-rio.br> wrote:
>> Are there any use cases where allowing reading t[nil] or t[nan] is useful?
>
> t[nil] is what happens when you do t[x] and x is nil :-)
>
> This may or not be a programmer error: you may be trying to determine
> whether a field given by the user exists in a table. If the user does
> not define the name of that field, then it's nil and you get t[nil].
> Not too common an idiom, though.
>

Exactly. We rely on this behaviour in quite a few places in our code.
Otherwise we would have to explicitly guard such accesses with a nil
check.

I don't want this to throw an error, but I'm not sure how /setting/ a
nil could be handled any different than it is today. The logic I use
is that there is no key for nil (hence it returns nil) and you can't
set it because it happens to be an invalid key.

Matthew