lua-users home
lua-l archive

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



  [If someone has counterexamples to this -- cases where a "?" postfix operator that _isn't_ immediately followed by "." or "[" is a significant convenience -- please post them!]

The version of the hack I'm using myself is extended to allow '?(' -- which works exactly like the function call version of CoffeeScript's existential operator.  It is occasionally useful -- allowing things like

   drawfun[type]?(record)

to evaluate as

   (drawfun[type] or _nullop)(record)

Like the ?. and ?[ patches, it can be implemented cheaply, as a small patch to primaryexp().  But my current implementation is a fairly dirty kludge.  In the case that drawfun[type] is missing, I'll actually evaluate the symbol '_nullop'.  This works great as long as we can trust _nullop to be defined, but has the potential to cause all sorts of trouble otherwise.  I'm sure there are cleaner ways of writing it up -- but all the options I can think of are either less efficient, or involve much larger diffs.  And even with a clean implementation, I'm not entirely convinced ?( is a good feature to add to a language.  The obscurity/usefulness tradeoff doesn't seem nearly as favorable as the safe navigation operators'.

-Sven