[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Table Constructor Syntax
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 10 Jun 2003 19:24:44 -0300
John Passaniti wrote:
>This is illegal in Lua 5:
>
> t = { 1="hey", 2="ho" }
>
>It must be written like this:
>
> t = { [1]="hey", [2]="ho" }
>
>The question is why. I assume there is some ambiguity that is being
>addressed here, but I can't see it.
Do you mean to use just number as indices? If so, I think there's no ambiguity.
But if you mean to use any expression, then the second syntax is cleaner and
easier to parse. Otherwise, consider this:
x = 23
t = { x = 100 }
What would this mean? Which field will have value 100, t[23] or t["x"]?
So, the [...]=... syntax comes to address simplicity and generality.
--lhf