• Subject: Re: Long chains of objects (aka tables)
• From: "Thomas Jericke" <tjericke@...>
• Date: Sun, 18 May 2014 19:48:41 +0200

```
-----Original Message-----
> From: "Thiago L." <fakedme@gmail.com>
> To: "Lua mailing list" <lua-l@lists.lua.org>
> Date: 18-05-2014 17:24
> Subject: Re: Long chains of objects (aka tables)
>
> On 18/05/2014 11:54, Thomas Jericke wrote:
> >
> > 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
> >
> >
> >
> >
> >
> So you want ? to make a fake nil with a metatable which returns nil
> whatever you do?

Actually I would make code that just skips all following operations of that statement and return nil.
But yes it would be about the same.

>
> Also have you tried: boolean = unpack(boolean ~= nil and {boolean} or
> {true})

No, I tried:
if boolean == nil then
boolean = true
end

You may call me conservative, but this does the trick
and people actually understand the code when they read it.
--
Thomas

```