[fpc-devel] if-then-else expression
Sven Barth
pascaldragon at googlemail.com
Thu Sep 4 08:05:29 CEST 2025
Michael Van Canneyt via fpc-devel <fpc-devel at lists.freepascal.org> schrieb
am Di., 2. Sep. 2025, 14:28:
>
>
> On Tue, 2 Sep 2025, Sven Barth via fpc-devel wrote:
>
> > Hairy Pixels via fpc-devel <fpc-devel at lists.freepascal.org> schrieb am
> Di.,
> > 2. Sep. 2025, 09:50:
> >
> >> On Sep 1, 2025 at 3:44:17 PM, Nikolay Nikolov via fpc-devel <
> >> fpc-devel at lists.freepascal.org> wrote:
> >>
> >>> 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;
> >>>
> >>>
> >> Yes I agree but in C-like languages I do use it in function parameters
> >> just as often. Still feeling like IfThen if made a real intrinsic would
> be
> >> most readable and Pascal-like. Since this new expression exists now
> making
> >> the intrinsic would be extremely trivial.
> >>
> >
> > It doesn't matter whether it's trivial or not. An IfThen() intrinsic
> would
> > have a different behavior from *any* other function-like element and thus
> > would be a bad idea. Thus there will be *no* auch intrinsic.
>
> I don't think this is a good argument:
>
> Write(), Writeln, WriteStr and Str() are also intrinsics with "different
> behaviour" from all other function, intrinsic or not:
>
> The : formatting for one, and some arbitrarily limited varargs-like
> behaviour for another.
>
> Yet these are firmly entrenched in pascal.
>
> So at least on these grounds, the IfThen() has as much reason for
> existence as these
> "real pascal" functions, in my opinion.
>
But that's also not a reason that there should be more intrinsics that
behave different from normal functions.
Also none of these you mentioned have a behavior like the IfThen()
intrinsic would have and some people might not even know that the
parameters can be adjusted with the ":" syntax (or even if they do they
might not need to use it; I don't know when I last used that for example),
but for IfThen() that is a core part of the behavior.
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20250904/b87e7d61/attachment.htm>
More information about the fpc-devel
mailing list