[fpc-devel] if-then-else expression

Nikolay Nikolov nickysn at gmail.com
Mon Sep 1 10:44:17 CEST 2025


On 8/29/25 5:30 PM, Hairy Pixels via fpc-devel wrote:
> On Aug 28, 2025 at 5:10:56 AM, Sven Barth via fpc-devel 
> <fpc-devel at lists.freepascal.org> wrote:
>> Also there *will* be the if-then-expression, the question is only 
>> when the merge request is finalized enough (I currently can't check, 
>> so I can't comment on any progress there).
>
>
> I didn’t realize it was imminent.
>
> What about this:
>
>   if (if x > 10 then 1 else -1) > 0 then
>     ;
>
> You can do confusing things like this too right? I don’t think we’re 
> going to avoid confusion with the intrinsic or this syntax.

Yes, that would become valid syntax. However, I doubt you're gonna see 
such code anytime soon, outside of obfuscated code contests (or vibe 
coded AI slop). Your nested if example is pointless, because it is 
equivalent to the much simpler:

if x > 10 then

   ;


You're more likely to see things like:

a := if x > 10 then 1 else -1;

instead of

if x > 10 then
   a := 1
else

   a := -1;

At least that's what I see in Rust code, which has a similar "if" as an 
expression, as well as a "if" as a statement. People who have the 
tendency to like functional programming tend to prefer the first form.


Every feature can be abused to write ugly code, but this one is not so 
bad, actually.


Nikolay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20250901/3da3e858/attachment.htm>


More information about the fpc-devel mailing list