lua-users home
lua-l archive

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


2011/9/19 Xavier Wang <weasley.wx@gmail.com>:
> 2011/9/17 Dirk Laurie <dpl@sun.ac.za>:
>> On Fri, Sep 16, 2011 at 10:12:50PM +0200, Javier Guerra Giraldez wrote:
>>>
>>> as much as i'd like to see real tuples in Lua (as the type of ... ),
>>
>> Let me take this wish seriously, if only because I hate the kludgy
>> look of `select'#'`.
>>
>> Syntax problems:
>>  - We can use `(1,2,3)` for a tuple with elements 1,2,3, but we can't
>>    use `(...)` to turn `...` into a first-class value because the
>>    notation already means something else (the first element of `...`).
>>  - We can use `[1,2,3]` for a tuple with elements 1,2,3, and by
>>    analogy with tables would then want to write func[1,2,3], not
>>    func([1,2,3]).  But how does Lua know that we want to invoke
>>    __call rather than __index?
>> Semantic problems:
>>  - Suppose `a` is a tuple with elements 1,2,3, and `f` a function.
>>    Is `f(a)` supposed to be equivalent to `f(1,2,3)`?
>>  - `...` is a name for a group of entries on the local stack.
>>    It is not a first-class value any more than `a` is a first-class
>>    value when you say `local a`.
>>
>> Solution:
>>
>> Syntax:
>>  - `tuple(...)` turns `...` into a first-class value.
>>  - `totuple(a)` turns a proper list into a tuple.
>> Semantics:
>>  - `tuple` is a userdata, with metamethods to implement __index,
>>    __len, __concat (maybe more?)
>> Implementation:
>>  - a nice little add-on module written in C
>>
>> Wait — surely someone has done almost exactly this already?
>>
>> Dirk
>>
>>
>>
>>
>>
>>
> There is a problem. we can not use a tuple to call function, if a is a
> tuple(1,2,3), so f(a) is the same as f(1,2,3) is normal, and f(a, a)
> is the same of f(1,2,3,1,2,3) is normal, We can not do that if tuple
> is just a userdata.
>
> I think we can introduce the data type tuple in Lua 5.2, it can be
> first-class type or not (I prefer not), I like the solution by
> somebody in list, that use a special syntax for tuple, maybe use
> var... is better. and makes tuple is only a range of stack.
>
> there are two definition of tuple: a first-class datatype or a range
> of stack. all has advantage and disadvantage, we can disscuss that,
> but first we need a plan to add light-weight tuple to Lua language.
>
Sorry for send mail twice, I mean  I think we can introduce the data
type tuple in Lua 5.3. Sorry.