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

Родион Горковенко <[email protected]> Sat, 27 Jun 2026 09:15:58 +0300
Newsgroups gmane.comp.lang.lua.general
Message-ID <CAL2n1tzqW7YMKXsw+qcABAbp_ixDCUHk3Q_gDDt+P591TuMRaA@mail.gmail.com>
Calimero, Hi!

Thanks for clarifications. I also have seen your discussion with Andrew
about readability etc.

However I probably failed to clarify my question of internal statements and
why I think your proposed change is really immense, not a syntactic sugar.

Your suggested feature allows us to create new variables inside the
expression, i.e. expression will affect outer scope.

a = if x > 1 then b = 13 end

Unless I had forgotten something or we use dirty tricks on globals table ,
expressions are restricted from such behavior.

So you actually propose to create completely new semantics of
expression/statements (or something in-between).

This is significant change from the viewpoint both of the source code and
of the language paradigm. Do we really need this?

Perhaps we may want something different for ternary operator?

What you propose, blocks with value calculated by the last statement,
surely exists in other languages but I think generally with languages which
use isolated scope for blocks.

sincerely yours,
Rodion

On Fri, Jun 26, 2026 at 11:17 AM 'Calimero' via lua-l <
[email protected]> wrote:

> Hello! Here's a explicit recap of the answers to your concerns:
>
> On 26/06/2026 09:44, Родион Горковенко wrote:
> > You probably may need to explain how it makes language "more powerful"
> as it seemingly duplicates existing "and / or" approach.
> The and/or approach has its caveats with falsy values that a proper
> if-then-else construct does not have.
>
> http://lua-users.org/wiki/TernaryOperator says :
> >The main caveat is that if |a| or |c| evaluates to true while |b| or |d|
> respectively evaluate to false, then this expression will not behave
> exactly like the ternary operator.
>
> > Proposed "if expression" may be more argued as "more readable" but it
> will anyway bring a number of issues - "if statement" allows multiple
> expressions inside (including variables definition) - how do you suggest to
> manage this in "if expression"?
> This is my suggestion to handle multiple statements:
> >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).
>
> And to complete it, I could add that any statement that is not an
> expression (like a variable definition indeed) can be considered to have
> the value `nil`.
>
> > So "it won't make language bigger" actually is a bit superficial glance.
>
> What I mean by bigger is if it is one more syntactic feature.
> Removing the current if statement and adding an if expression (that
> supersedes it perfectly) would not increase the total count of syntactic
> features!
>
> This is what I meant by "not making the language bigger".
>
>
> --
> 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/6347a9ea-2bf8-7fdb-c59a-8d4d93ead14a%40free.fr
> .
>

-- 
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/CAL2n1tzqW7YMKXsw%2BqcABAbp_ixDCUHk3Q_gDDt%2BP591TuMRaA%40mail.gmail.com.