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

Martin fpc at mfriebe.de
Mon Feb 1 21:19:15 CET 2016


On 01/02/2016 19:33, Marcos Douglas wrote:
> V := inline If Condition then ThenExpr else ElseExpr;
>
ignoring the "inline"

There are 3 styles (ignoring the names of identifiers used), can think of

1) function
   x :=  IfThen(a,b,c);

2) statement with return value
   x :=  If a Then b else c;

3) ternary operator
having 3 arguments, it needs at least 2 tokens to separate them
   x :=  a IfThen b else c;
Of course the operator can have a leading token, and the statement 
syntax could be an operator.


In cases 2 and 3 (operator) precedences become an issue (unless a 
terminating "end" is required)
   x :=  If a Then b else c + 3;
should be which
   x :=  (If a Then b else c) + 3;
   x :=   If a Then b else (c + 3);

So function style has the build in clarity on this. But it can be 
confused with existing functions of the same name.





More information about the fpc-pascal mailing list