lua-users home
lua-l archive

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

How about just change the existing if-then-else-end to become a ternary operator?

local successful = if result==1 then void_func1(); bool_func2() eiseif result==2 then do_this(); false; else bool_func3() end

It returns the last thing in the block, just like lisp's "cond".

Big change, but IMO more elegant.


On 11/09/2010, at 8:04 PM, Duncan Cross wrote:

On Sat, Sep 11, 2010 at 7:18 AM, Alexander Gladysh <> wrote:
Do we *really* need a ternary operator in Lua?

Well, there are already plenty of things already in the language that
we don't *really* need:
- a:b()
- repeat <x> until y
- Multiple return values
- The operators <, <= and ~=

...and so on. If we didn't have these we could always find ways to
work around them. But the workarounds would have pitfalls, just as "a
and b or c" does, and would make Lua code that bit less pleasant to
write. As simple and slender as Lua is, it is not aggressively so, to
the point that absolutely nothing nonessential is allowed in.