lua-users home
lua-l archive

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

function choose(expr, [x], [y])
 -- x and y are functions that must be called to get their value.
 if expr return x() else return y() end

That's what I was thinking... Feeling stupid, don't know what got into me to think it wouldn't work just like that. 

I think this is not a good feature since it is not clear to the
caller whether the expressions will be both evaluated or not.  Michal
Kottman already provided a better example:

z = choose(y~=0, [x/y], [0])
IMO this is more clear than 
z = choose(y~=0, || x/y, || 0)
But would it conflict with the array indexing operator i.e the brackets in "myarray[5]"?