lua-users home
lua-l archive

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


On 09/07/15 17:16, Roberto Ierusalimschy wrote:
...<snip>...
>> a = { b = { c = 123 } }
>>
>> print( maybe(a).b.c() )  -- 123
>> print( maybe(a).x.c() )  -- nil
>>
>> --
>>
>> I'm not 100% happy with it, but I think it'd cover most my use cases.
> 
> When all fields are present, that code will create two new tables plus
> two new closures at each dot: for instance, maybe(a).b.c() creates four
> new objects. That sounds quite expensive.


Yeah, you wouldn't want it in any performance code, which is the main
reason I'm not happy with it. Fortunately for me raw performance isn't
an issue where it might be used, where as readability (and ease of
editing) is.

Please do the a?b?c idea in 5.4/6.0 :)

Scott