lua-users home
lua-l archive

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


Someone better at searching the archives will find the post where I raised this before, but what I've wanted on occasion includes:

	a?.b -- evaluates to a.b if a is not nil; evaluates to nil if a is nil
	a?:m() -- calls a:m() if a is not nil; simply evaluates to nothing if a is nil (or nil if in a context where a value is needed)
		-- This is inspired by the Objective-C behavior of allowing one to send messages to nil and have it do nothing
	a:?m() -- call a:m() if a.m is not nil; evaluates to nothing if a.m is nil
	a?:?m() -- a can safely be nil or can fail to have the method m defined

The question that arises is when this starts to look too much like line noise. On the other hand, writing out the various tests and control constructs -- particularly if doing something that could be handled via chaining -- is noisy in a different way that also obscures meaning.

Mark