lua-users home
lua-l archive

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



.. or "?.", and then similarly "?[...]"  ?

Now that I hadn't thought of.  It reads a lot better than a plain "?":
    object?.icon?.glow?.color  

And the meaning is certainly clearer than "~".  I'm also enjoying the reference to C's ternary op.  

I think I'm convinced :)

But the dangerous thing about this is that it's suggesting a more general semantic -- specifically, making '?' a postfix unary operator that returns the empty set if its argument is nil or false.

Then we could have tricks like
   for c in pairs(colors?) do

The idea starts to fall apart when you try to figure out how, exactly, to represent the empty set.  Allowing 'colors?' to be writeable is asking for trouble.  In my own scripts, I define
   _empty = setmetatable({} ,{ __newindex=function() end } )

But of course, as long as it's a proper lua table, there's always a risk of rawset, and referencing '_empty' inside lparser.c would be an ugly kludge.

Even so, the idea has a certain elegance...

-Sven