lua-users home
lua-l archive

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


The # operator could be overridden with a token filter I beleive.
wes

On 7/30/07, Jerome Vuarand <jerome.vuarand@ubisoft.com> wrote:
> John Belmonte wrote:
> > Programming in Lua refers to nil in a list as a "hole", but that is
> > from the perspective of Lua's table representation which cannot
> > distinguish nil-valued from nonexistent keys.  From the view of the
> > list creator, why should either of the following be considered as
> > having holes?
>
> I think part of the problem comes from the fact that some people
> distinguish nil-valued from non-existent keys. But the concept of a
> non-existent key is not applicable to Lua tables. In Lua a table is an
> infinite associative array, with all possible keys having a value. By
> default all keys have a nil value. These nils are not explicitly stored,
> but that's an implementation detail.
>
> In that context the # operator is not well defined. I see two good
> (though not perfect) solutions: either make the table # operator
> deterministic (for example return the biggest integer key), or allow
> users to override the # operator (that's my prefered solution, since it
> would be useful for other problems, like returning the norm of a
> vector).
>