lua-users home
lua-l archive

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


2010/9/16 Tom N Harris <telliamed@whoopdedo.org>
But should this have higher or lower precedence than comma? (As mentioned by David M. a few days ago <http://lua-users.org/lists/lua-l/2010-09/msg00360.html>) What does this statement mean?

A,B = if C either D or E,F

I understand that in Lua, comma is not operator.  It's a separator for multiple variable/value in an assignment statement,  a separator for function arguments, a separator for multiple value in a return statement, and so on.  Comma is not an operator, so there is no problem about operator priorities.  Comma can separate expressions, but Comma cannot be included in an _expression_.  So above line will be:

if C then A,B = D,F else A,B = E,F end
  
The real question is, if Lua doesn't get a ternary operator, what will be more of a problem? Responding to requests for a ternary operator on the list, or correcting people who type "LUA"?

There are two benefits of a ternary operator, I think.
- For an assignment statement, you have to write left term only once if you can use a ternary operator.  This is emphasis when the left term is long and complex.
- The script code and compiled binary is shorter than other notation. So the code will run fast.

And people think "Other major languages have a ternary operator, but why Lua not?"

Thank you 
Ryota Hirose