[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: new "empty" value/type in Lua?
- From: "Pierre Chapuis" <catwell@...>
- Date: Tue, 2 Jul 2013 18:21:33 +0200
> 2013/7/2 Thomas Jericke <tjericke@indel.ch>:
>
>> the array stores its length 'n' explicitly
>
> Come back, Lua 5.0! All is forgiven!
Why do you think we're suggesting that?
That being said in 5.0 it wasn't a type in its
own right, just a few functions that assumed
things in the table library.
Here's what I would like to see:
local a = sequence.new()
type(a) -- "sequence"
#a -- 0
a:insert(1)
a[#a+1] = {}
a[5] = 3
#a -- 5
a -- [1, {}, nil, nil, 3]
a.stuff -- error
a.n -- error (use #)
What a[0] and a[-1] would be should be discussed.
Personally, I would go with a[0] being *an error*
and a[-1] being 3.
We would also pass a table to the constructor to
convert it to an sequence (for backwards
compatibility and easier initialization):
a = sequence.new{1,5,9}
I don't really care about the name (I used sequence
in the example to avoid the real candidates:
vector, list, array...)
--
Pierre Chapuis