lua-users home
lua-l archive

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


2011/9/16 steve donovan <steve.j.donovan@gmail.com>:
> On Fri, Sep 16, 2011 at 7:48 AM, Dirk Laurie <dpl@sun.ac.za> wrote:
>> So: sometimes good, sometimes bad.
>
> Actually, such a patch would be still useful for embedders that need
> to squeeze some space efficiency out of their customized Lua, without
> actually getting into mainline Lua.  Lua has a very accepting
> patch-culture.
>
> What's interesting is that it provides a possible answer to the
> question "what is ...?'. If ... is implemented as a Xavier-tuple, then
> it must behave like a variable-list:
>
> local a,b,c = ...
> local args = {...}
> local a = select(1,...)
>
> What completes the picture and makes ... a first class value is if
> there is a function or construct that allows it to be treated as a
> value:
>
> local args = @... (or just tuple(...); we don't need a new sigil, but
> a function call would be more expensive)
>
> Then 'args' now has type 'tuple'.  Having a distinct new type means
> that it gets a shared metatable and one can establish suitable
> equality semantics etc.
>
> steve d.
>
>
Yes, originally I'm think about to add a new data type to Lua, but I
can imagine what the worlds of the authors of Lua :) So I decide to
made it with a more "helpness" way.

long long ago I'm want to wirte this kind of code:
function foo() return 1,2,3,4,5 end
local a, b, c, d, e = foo()
local a, ..., e = foo()
local a, x..., e = foo()
local b, c, d = x...

this is a kind of "tuple", but not a true data type, it's just a range
on Lua stack, it's very cheap, but very difficult to implement. it
turns out all function arguments are tuples, and can be construct in
this way. this will makes function call very flexible. and because its
just a range of Lua stack, not a true type, so it's use less memory
(even don't need allocate memory for it!).

the patch-ev is just another way to implement a "easier" tuple.