lua-users home
lua-l archive

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


> On Jun 27, 2016, at 10:29 AM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> 
>> Bingo! I'd say an `n` key with an integer value greater than or
>> equal to 0, but let's not nitpick. I also think this would have been
>> a viable alternative to the sequence concept we now have, because it
>> has some useful properties:
>> 
>> *  [...]
> 
> Something that seems to be missing in this discussion is constructors:
> 
>   l = {1, 2, 3, 4, 5}
>   print(#l)          --> ?  (no 'l.n'...)
> 

I did mention it in my earlier post…

"I’m undecided if a table initializer should set the size: should {1,2} have a size of 0 or 2? What about more complex initializers? And of course there are issues with non-integral keys etc.”

There is probably no easy answer to this one. I suppose you could argue that a “pure” array constructor (one that had only implicit keys) can assume an array and set the size accordingly, while all others do not, but I’m not sure that passes the “least surprise” principal.

But I still stand by my original point: the entire sequence concept and meaning of # (and the hold-out of of “.n”) seems to me one of the more frequent areas of confusion for people new to Lua .. and in fact there was another post only today on this very issue.

—Tim