lua-users home
lua-l archive

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


On Mon, Jul 25, 2016 at 12:36 PM, Egor Skriptunoff
<egor.skriptunoff@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.

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

Hm, then why not `local tbl, n = table.pack(...)?

When I see awkwardness, I tend to wrap over it. Tuples have been on my
mind recently. In Penlight (soon for new release) I simply extended an
existing tuple type, which was used as a testing convenience:

https://github.com/stevedonovan/Penlight/blob/master/lua/pl/test.lua#L112

That is, override __len and let it know about table.unpack.

Then:
local T = require 'pl.test'.tuple

function foo(...)
   local args = T(...)
   for i = 1,#args do
     ...
   end
   --- forwarding
   boo(args:unpack())
end

Not suggesting this as any kind of canonical solution, but it hides
that .n which annoys people so much.