lua-users home
lua-l archive

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



-----Original Message----- 
> From: "Philipp Janda" <siffiejoe@gmx.net> 
> 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`
> 
> >
> > -Andrew
> >
> 
> Philipp
> 
>
Any structure that is more of a tree than a namespace structure will easily a depth of 5 or more.

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

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