[fpc-pascal] New feature: IfThen() intrinsic

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Tue Feb 2 11:41:55 CET 2016


Michael Van Canneyt wrote:

> Call me old fashioned, but then I think
>   foo:=iif(Condition1,
>            iif(Condition2, ThenExpr1, ElseExpr1),
>            iif(Condition3, ThenExpr2, ElseExpr2));
> is more clear.
> 
> 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.

If we want to organise it so that FPC can only evaluate function 
parameters when required, then it is necessary to implement ALGOL-60's 
"call by name" semantics, which were universally agreed to be deeply 
messy and perhaps not even what the standard authors intended.

-- 
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