lua-users home
lua-l archive

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


Jamie Webb wrote:
On Wed, Aug 18, 2004 at 04:22:11PM -0700, Marc Nijdam wrote:
  
Rici Lake wrote:

    
a = {
 b = {
   c = 22
 }
}

--> semicolons shouldn't appear in table constructors, although you 
can write a comma as a semicolon for backwards compatibility.
      
I know the above syntax works, but why doesn't the syntax I use below?
    
Why would it? It's nonsensical; trying to do something imperative
inside a declarative construct. And the syntax definition does not
permit it. You're misreading.
  
Hmmm, I agree it's non-sensical if you think of it as imperative. It just appears asymetrical when at the top level you can do

a = {
  b = {}
};

a.b.c = 22

but not in the table declaration, which to me looks the same as a nested 'top' level. I guess that's where I'm wrong.

You are right about misreading the bnf though.
field ::= `[´ exp `]´ `=´ exp | name `=´ exp | exp

the only syntactically correct way to try to do what I want is to do the following:

a = {
   b = {};
   [b.c] = 22
}

which give "b not defined globally". Placing 'a' in front of this shows why this is declarative.. a is not defined yet.

Thanks for the slap, feel much better now :-)

--Marc