Re: Replacing the "if" statement with an "if" expression which supersedes it

Luther Thompson <[email protected]> Sat, 27 Jun 2026 06:12:59 -0700 (PDT)
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
I should point out that Lua does not allow an expression to be a statement 
(unless it's a function call), so letting the last statement of a block be 
the value of that block would be a major change in the grammar.

Also, while I'd love to see a true ternary operator in Lua, it is 
fundamentally different from an if-else statement, and I don't think they 
should be unified. A ternary operator is a single expression resolving to a 
single value. An if-else can contain multiple statements, which makes 
side-effects more likely to happen.

Luther

On Thursday, June 25, 2026 at 8:41:26 PM UTC-4 Calimero wrote:

> Hello!
>
> I suggest outright replacing Lua's existing "if statement" with an "if 
> expression".
> The expression variant would completely supersede the current statement 
> variant, keeping exactly the same syntax.
> This does not make the language bigger, but it does make it more powerful.
>
> It would be a fully backwards-compatible change, with the value of the 
> expression being simply ignored in existing codebases.
>
> Details:
> - Lack of an "else" branch would simply mean the value to be "nil" if no 
> condition is true (in if or elseif branches).
> - This drags along with it the idea that a block of statements evaluates 
> to the value of its latest statement (possibly nil, if no value).
>
>
> Naturally, I have read http://lua-users.org/wiki/TernaryOperator before 
> posting this.
>
> I am interested in knowing whether this will be implemented, or failing 
> that, why it won't be!
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/d5fc682a-f1af-4397-aea7-9e61f21ab88dn%40googlegroups.com.