Re: Replacing the "if" statement with an "if" expression which supersedes it
Andrey Dobrovolsky <[email protected]> Fri, 26 Jun 2026 19:36:03 +0300
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <CAN5FJ7cnVNXbnOf0ukDaWiPo9Gn_wGavHtWxvVcK=8_QRD+4cw@mail.gmail.com> |
Hi Calimero,
Really parentheses are not enough. Dealing with variables (not some
constants) require more boilerplate:
a and b or (b and c)
-- Andrew
пт, 26 черв. 2026 р. о 18:44 'Calimero' via lua-l <[email protected]> пише:
>
> Le 26/06/2026 à 17:32, Andrey Dobrovolsky a écrit :
> > Greetings!
> >
> >> 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.
> > In my understanding it is not a "caveat" (opinionated) but lack of parentheses.
> >
> > Regards,
> > -- Andrew
>
>
> Well, not quite!
> The caveat is still present with extra parentheses, that I can tell:
>
> > (10 < 11) and ("yes") or ("no")
> yes
> > (10 < 11) and (false) or (0)
> 0
>
> Can you fix the second example to return `false` as it should, by adding some parentheses? I experimented but failed.
>
>
>
> To digress and be entirely honest, the other (and main) caveat of `condition and a or b` is that readability suffers, because objectively it is not stating its intention!
> And when it's nested, I feel a bit lost: `x = a and b or c and d or e`
>
> Cheers
>
>
> --
> 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/c2d70b8b-5b43-0e2b-2130-868782ccff30%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/CAN5FJ7cnVNXbnOf0ukDaWiPo9Gn_wGavHtWxvVcK%3D8_QRD%2B4cw%40mail.gmail.com.