Re: Replacing the "if" statement with an "if" expression which supersedes it
Andrey Dobrovolsky <[email protected]> Fri, 26 Jun 2026 21:08:07 +0300
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <CAN5FJ7fz+sQbbnXkKdZJPsHHpgnYDT2nfyq4eeF+Mv7OedQeLw@mail.gmail.com> |
Hi Calimero,
I'm glad that You like community proposed snippets so much. I'd like
to propose a pair of even easier to understand
(select(a and 1 or 2, b, c))
({[true] = b, [false] = c})[a]
Hope You'll enjoy ))
-- Andrew
пт, 26 черв. 2026 р. о 20:16 'Calimero' via lua-l <[email protected]> пише:
>
> Le 26/06/2026 à 18:50, Paul K a écrit :
> > Hi Calimero,
> >
> > On Fri, Jun 26, 2026 at 8:44 AM 'Calimero' via lua-l
> > <[email protected]> wrote:
> >> Le 26/06/2026 à 17:32, Andrey Dobrovolsky a écrit :
> >>> (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.
> > I usually just negate the condition when I run into this situation:
> >
> >> not(10 < 11) and (0) or (false)
> > false
> >
> > Paul.
>
> My brain hurts seeing this!
> I would be fine if it were hurting because I made it work hard to produce code that is easily understandable, but this is not it.
>
> These contorsions in fact illustrate very well why I want to keep the existing conditional syntax (except now it has a value): `if 10 < 11 then false else 0 end` is so much clearer.
> I need my attention on the programming, not on the coding, and I think so do many of us!
>
> --
> 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/0971056a-9c95-5266-dbde-3ace8b1dab86%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/CAN5FJ7fz%2BsQbbnXkKdZJPsHHpgnYDT2nfyq4eeF%2BMv7OedQeLw%40mail.gmail.com.