lua-users home
lua-l archive

Re: Multiple indexing (was: 'in' keyword today)

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


On 04/10/2014 10:04 PM, Sean Conner wrote:
It was thus said that the Great Thomas Jericke once stated:
-----Original Message-----
From: "Sean Conner" <sean@conman.org>
 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]
 Interesting. Because in my mind, I was parsing it as
	a,b,c in foo = (x,y,z in bar) in baz
 (left to right) That is:
	foo.a = baz[bar.x]
	foo.b = baz[bar.y]
	foo.c = baz[bar.z]
 I'm not saying I'm right or you are wrong, just how I would interpet it.
 -spc (Anybody? Anybody? Bueller? Bueller?)
You have a mistake in you inner interpreter right there
I wrote:
a,b,c in table -> table["a", "b", "c"]
If you want to expand left to right you get
a,b,c in foo = (x,y,z in bar) in baz
foo["a", "b", "c"] = (bar["x, y, z"]) in bat -- syntax error: name expected near "(bar["x, y, z"])" The statements in front of the in must be names not expressions, if you start to mix them the code will get ambiguous. Example:
local t = {}
local table = { t = "lala" }
table[t] = "dada"
local test = t in table
print (test) -- lala or dada ?
--
Thomas

AltStyle によって変換されたページ (->オリジナル) /