[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why is nil not a valid table key?
- From: Rici Lake <lua@...>
- Date: Sat, 26 Nov 2005 09:28:36 -0500
On 26-Nov-05, at 4:54 AM, Wim Couwenberg wrote:
If nil is in the range, then surely *all* values are in the domain?
;-)
Yes, that was my point. Considering gettable as a function, the range
is <all values> and the domain is all pairs t, k such that t is a table
and k is any value. (Leaving aside things with metatables for now). But
settable differs, in that the domain of the second argument does not
include nil (or NaNs).
If we return to metatables, we'll see that __index(t, k) can receive
nil as its second argument, but __newindex(t, k, v) cannot.
That is the sense in which I say that nil is not in the domain.
eg.
> foo = setmetatable({}, {__index = print, __newindex = print})
> =foo[nil]
table: 0x808c400 nil
nil
> foo[nil] = 3
stdin:1: table index is nil
stack traceback:
stdin:1: in main chunk
[C]: ?