[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: tables holding nil: another way to look at the question itself
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Fri, 24 Jul 2009 16:15:04 +0200
2009/7/24 Jim Jennings <jennings.durham.nc+lua@gmail.com>:
> Cosmin Apreutesei <cosmin.apreutesei@gmail.com> wrote:
>
> [...]
>
> This corresponds to an intuitive definition such as this one: "The
> expression a[k] returns what is in table a at index k. Since nil is
> an illegal index, there can be no value stored at a[nil], and 'no
> value' in Lua is represented by nil. So, a[nil]==nil."
You can always turn the problem one way or the other to have your
prefered solution look more or less natural. For me Lua tables are
infinite sets of key-value pairs, with any Lua object associated with
another one. And I'm just considering the pair with nil as key is a
read-only pair. For consistency I'd rather have it writable, but the
guarantee that the value nil is always associated to the key nil
simplifies a lot some other uses of tables (eg. iteration over pairs
with a non-nil value, which is a frequent operation).