lua-users home
lua-l archive

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



On Mar 3, 2013, at 2:24 PM, Hadriel Kaplan <HKaplan@acmepacket.com>
 wrote:


On Mar 3, 2013, at 1:28 PM, Sven Olsen <sven2718@gmail.com> wrote:

print( config.color? )  --> should print false not nil

This is the big potential drawback I can see for my _SAFE approach.  While the syntax is shared with CoffeeScript's existential operator, the semantics are different.  As I'm defining it, ? is a utility for safe table navigation -- it shouldn't be used to check for existence.  "config.color?" is prettymuch guaranteed to never be nil or false, as it's just shorthand for "(config.color or _SAFE)".

You could have the patch do this:
function __check(expr)
if type(expr)=='boolean' then
return expr
else
return _SAFE
end
end

and convert:
expr? to (expr or __check(expr))

Or make the function this:
function __check(expr)
if expr == nil then return _SAFE else return expr end
end

Probably faster.

-hadriel