lua-users home
lua-l archive

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


On Mon, Jul 25, 2016 at 2:02 PM, steve donovan <steve.j.donovan@gmail.com> wrote:
> The "holes problem" exists only in the context of sequences,
> so introducing "null" type is not a good idea as it affects the whole
> language.

It would not be a type - it would be equivalent to you having declared
'null = {}'. It becomes a convention that module writers can depend
on.

What would ({})[1] be equal to: null or nil?


BTW, "null" may be a function which can be used to check for equality to itself:

-- Definition
local function _NIL (value) return value == _NIL or value == nil end
_G._NIL = _NIL

-- Usage
if not _NIL(v) then ... end


 
> local tbl, idx_from, idx_to = table.pack(...)

Hm, then why not `local tbl, n = table.pack(...)?
 
1) For symmetry:
table.unpack(table.pack()) should be an identity

2) For storing sequence in a single value (to make array of sequences, for example):
-- tuple to single value
local v = {table.pack(...)}
-- tuple from single value :-)
forward(table.unpack(table.unpack(v)))