[fpc-pascal] New feature: IfThen() intrinsic
Mark Morgan Lloyd
markMLl.fpc-pascal at telemetry.co.uk
Tue Feb 2 12:48:03 CET 2016
Michael Van Canneyt wrote:
> On Tue, 2 Feb 2016, Mark Morgan Lloyd wrote:
>>> The "if then" construct is really confusing.
>>> "if then" is a statement, not an expression.
>>
>> Yes, and that's why to get the desired semantics it's more appropriate
>> to use if then else rather than iif() etc.
>>
>> Please correct me if I'm wrong, but my understanding is that in all
>> cases where parameters are passed to a procedure or function they are
>> evaluated and placed on the stack before the code is called. However
>> the if then else statement never, under any circumstances, executes
>> code in the untaken statement/block, and it is that which is the
>> required behaviour for an "inline if" expression.
>
> I cannot remember a single case in 25+ years where I had to pay
> attention to this.
>
> I think that people who rely on the order of the arguments evaluation
> need to rethink/restructure their code, because their code is IMHO
> fundamentally flawed: it is not robust at all.
As Jonas points, out, this is absolutely nothing to do with order of
evaluation (unless, by some stretch of semantics, you fold "whether"
into "order" :-)
The only way that you can fairly implement an ifthen() or, in the
general case, some sort of select() function, is if you convert the
code fragments to be executed into anonymous functions and pass
references to those as individuals or as an array for late evaluation.
And that's basically the sort of hack that was derided in ALGOL.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-pascal
mailing list