lua-users home
lua-l archive

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


I'm replying off list because I don't have time to verify that it works 100% the way I think it does.

On 02/28/2013 01:14 AM, Dirk Laurie wrote:
A lollipop is a kind of sugar that is specially designed to suck.
Even C cannot be excused (you_agree? great : get_stuffed).
What do you think the ternary operator is "sugar" for? I /can/ only think of it being abused as an if/else replacement, but it's actually quite elegant when used for assignment:
int x = a ? b : c;

It's much cleaner than:
int x;
if(a) x= b;
else x = c;

The same basic thing can be done in Lua as well:
> a=true
> b=5
> c=10
> x= a and b or c
> print(x)
5
> a=false
> x= a and b or c
> print(x)
10