lua-users home
lua-l archive

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



I must be missing something, but why can't you just do this with a metatable and skip the syntactic sugar altogether?

Well, the thought is that a specialized syntax could provide a useful degree of fine grain control.  Whether or not to throw an error in response to an undefined reference isn't necessarily a natural a property of tables. 

In some ways a '!.' syntax feels like the natural inverse of the "safe navigation" sugar I posted a few weeks back.  In situations where silently returning nil is desirable, you can write:

a=node?.parent?.name

But if the situation recommends loud failures, you'd write:

a=node.parent!.name

In both cases, the error handling behavior is specified by the syntax of the call, rather than being stored as a trait of node.parent or the nil metatable.

But while the safe navigation patch is certainly one that I like, I'm not yet convinced that it's inverse is really worth the trouble.  In a moment of procrastination, I went ahead and wrote the feature into my own parser -- now I'll live with it for a few months and see if it proves useful in practice.

-Sven