lua-users home
lua-l archive

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

> Proposal 2
> ----------
> Leave tables as they are, but introduce more efficient mechanisms than
> select for dealing with varargs. Specifically, allow:


> Proposal 3
> ----------
> Tuples to capture sequences containing nil. This can be done with functions
> but they are crude because they don't support #tuple and tuple[ idx ]. This
> can be done with userdata but it gets a bit expensive and leaves open the
> question of why one needs to bail out to userdata to work around language
> "issues".

I think your proposal 3 would be an implementation of proposal 2 in the sense
that (functional) tuples could substitute select. Why would you need #tuple
and tuple[idx]? select does not have them, for instance. With tuples one could

> t =, 20, nil, {}, "foo")
> print(t"#")
> print(tuple.len(t))
> print(t())
10      20      nil     table: 0x8082d30        foo
> print(t(3))
nil     table: 0x8082d30        foo
> print(t(2,4))
20      nil     table: 0x8082d30

However, if #tuple and tuple[idx] are really needed, one could set a metatable
for functions:

> debug.setmetatable(t, {
>> __len = function(o) return o(0) end,
>> __index = function(o, k) return o(k, k) end})
> print(t[#t])


A mathematician is a device for turning coffee into theorems.
        -- P. Erdos 

Luis Carvalho
Applied Math PhD Student - Brown University
PGP Key: E820854A <>