[fpc-pascal] New feature: IfThen() intrinsic
Sven Barth
pascaldragon at googlemail.com
Tue Feb 2 14:20:00 CET 2016
Am 02.02.2016 11:42 schrieb "Mark Morgan Lloyd" <
markMLl.fpc-pascal at telemetry.co.uk>:
>
> 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.
Compiler intrinsics are not necessarily subject to these rules. Take for
example Assert: the string parameter whig can contain function calls is
only evaluated if assertions are active at all and the condition is false.
Same with the IfThen-intrinsic I had added, it only evalutes the branch
that is taken.
Please note that intrinsics are the exception, not the rule.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160202/22131620/attachment.html>
More information about the fpc-pascal
mailing list