lua-users home
lua-l archive

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


In message <46ABA94F.9030905@neggie.net> you 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?
>
>     x = { 2, nil, 'bar' }
>     t = { 2 }; table.insert(t, nil); table.insert(t, 'bar')
>
> Clearly they are not sparse as constructed.  Stepping back, a list is
> generally defined a series of values.  Lua nil is a first class value--
> an incredibly useful one-- which should not render lists practically
> useless.

There is a long history of confusion, even in the purely theoretical
considerations of the semantics of type theories, about bottom
elements denoting undefined data, exceptions etc. The difficulty seems
to be that nil is being stretched to rather a lot of uses. The
introduction of boolean values in Lua freed nil from having to represent
false. Is it not conceivable that the user may need lots of different
kinds of nil? For example

nil (= undefined),
nil (= you can go ahead and garbage collect),
nil (= error condition),
nil (= please keep this slot ready till I get round to filling it)

might in some circumstance need to be discriminated, perhaps?

-- 
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/