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

"'Calimero' via lua-l" <[email protected]> Sun, 28 Jun 2026 15:07:01 +0200
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
Le 27/06/2026 à 19:02, Francisco Olarte a écrit :
> The original extension was not specified nearly enough for me, and
> further clarificacions were not of much help, as they began to mix
> if-expressions with "(nearly) every statement is an expression", what
> allows C to do a=b=1.

Ouch no, I do not want "every statement is an expression". Statements should remain satements.

Thankfully, allowing *expressions* to qualify as statements doesn't allow something like a=b=1!

I think there is no need to say that statements must be expressions to achieve valued code blocks (and the if expression I propose as a drop-in replacement for the if statement).

The fact that a code block ending in a statement gives `nil` when we try to derive a value from it does not change this.
Statements still cannot be used as parts of an expression with just this.


Le 27/06/2026 à 19:11, Francisco Olarte a écrit :
> On Sat, 27 Jun 2026 at 18:56, 'Calimero' via lua-l
> <[email protected]> wrote:
>> The conditional is a very fundamental notion in programming, and there is a fundamental flaw in not having an expression conditional.
>> I'm trying to deal with this.
> The conditional is fundamental, the ternary ( or the funky IF
> expression I drafted previously ) is not.
No, the conditional expression is just as fundamental as the conditional statement.
They are even two instances of the same idea, which is why I suggest to make them the same entity.

Could you argue otherwise? (not involving personal preference for imperative code)


>  After all we put some men on
> the moon more than fifty years ago without ternaries ( take "we" as
> "the humanity", assume no foul play in the banner photos ). And lot of
> languages do not have them.
>
> If-expression is nice, but I would put it after op-assign in priority,
> and maybe after elvis. But before postincrement, if I ever did that
> one, and anyway to bne useful that need to redefine what a expression
> is first.
Well, we can all have a personal preference when it comes to priorities. (actually, as it concerns lua, I don't!)
Our personal preferences will just decide where we will each contribute our respective effort.

As long as the various ideas being worked on are compatible with one another, this is totally fine!

There are no interactions to discuss between op-assign and if-expression topics, I think?
As far as conditionals are concerned, op-assign is an instruction like any other, and as far as op-assign is concerned, if-expressions are an expression like any other.
If they are indeed unrelated, then there is surely no reason to discuss these unrelated features in this thread.

And in any case, on my end I have no intention to make any claims on what should be a priority in the development of lua.

> ( And I would vote against a pythonesque x if cond else y )
You didn't say your reasons, that would be interesting to know.

It just so happens that I agree with your opinion, and I can give my reason for that:
Lua already has a perfectly good conditional syntax, why should we need to invent another? Keep it simple!

-- 
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/54efae75-802a-19c5-bdd7-a5d85fd32cf1%40free.fr.