|
On 18/05/2014 11:54, Thomas Jericke wrote:
-----Original Message-----
From: "Philipp Janda" <siffiejoe@gmx.net>Any structure that is more of a tree than a namespace structure will easily a depth of 5 or more.
To: lua-l@lists.lua.org
Date: 18-05-2014 16:01
Subject: Re: Long chains of objects (aka tables)
What kind of data structures are you guys dealing with? The longest
sequence of fixed length with constant table lookups in my code is
`package.loaded.math`
-AndrewPhilipp
Think of stuff like DOM in _javascript_:
document.body.style.backgroundColor = "blue"
In our case we speak about machines:
Machine.Modules.Portal.Commands.MoveX(24)
if Machine.Modules.Portal.Properties.Width > 20
...
end
So you want ? to make a fake nil with a metatable which returns nil whatever you do?
We have lots of code that looks exactly like that. But most of the time,
raising an error is perfectly the right thing to do.
The ? operator looks interesting to me, but I think it would need to be more general.
Using it only for table lookups looks to limited to me.
I mean, what about things like:
X.Y?()
local res = X? + Z?
(res is nil if x is nil or z is nil)
And finally I ask myself if a similar syntax could possibly solve the default
value problem.
function do(boolean)
local boolean? = true -- assigns true if boolean is nil.
end
Remember "local boolean = boolean or true" does not the right thing!
A left hand side ? would break on not nil. So doing the opposite of the
right hand side. Well that may be confusing, so maybe we finally get a ¿ operator?
Disclaimer: I am just thinking out loud, this are neither suggestions nor proposals.
--
Thomas
Also have you tried: boolean = unpack(boolean ~= nil and {boolean} or {true})