lua-users home
lua-l archive

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



-----Original Message----- 
> From: "Sean Conner" <sean@conman.org> 
> To: "Lua mailing list" <lua-l@lists.lua.org> 
> Date: 10-04-2014 19:29 
> Subject: Re: Multiple indexing (was: 'in' keyword today) 
> 
> It was thus said that the Great Thomas Jericke once stated:
> > On 04/10/2014 09:38 AM, steve donovan wrote:
> > >It's a little awkward with string keys : t["one","two"], but not awful. 
> > 
> > Let's assume you could use the proposed "in" syntax for string keys:
> > 
> > Currently we have
> > 
> > t["one"]
> > and
> > t.one -> t["one"]
> > 
> > Additionally there would be:
> > t["one", "two"]
> > and
> > one, two in t -> t["one", "two"]
> 
>   Question:  What does the following mean?
> 
>      foo = { a = 1, b = 2, c = 3 }
>      bar = { x = 'one' , y = 'two' , z = 'three' }
> 
>      a,b,c in foo = x,y,z in bar
I am not really sure if I should answer any questions including the words "foo" and "bar" but I try.

It probably should expand to:
foo["a", "b", "x"] = bar["x", "y", "z"]

Now the question is what should:
foo["a", "b", "x"] = 1, 2, 3 mean? 
> 
>   How about:
> 
>      foo = { a = 1 , b = 2 , c = 3 }
>      bar = { x = 'one' , y = 'two' , z = 'three' }
>      baz = { one = 'alpha' , two = 'beta' , three = 'gamma' }
> 
>      a,b,c in foo = x,y,z in bar in baz

Depends on the order of the in operarator, IMO it should be right to left:

foo["a", "b", "x"] = baz["bar"]["x", "y", "z"] 

As  baz["bar"] is nil, you will get: 

attempt to index field bar (a nil value)I think what you wanted to write is:

a,b,c in foo =  baz[x,y,z in bar]

--
Thomas