[fpc-pascal] New feature: IfThen() intrinsic
Sven Barth
pascaldragon at googlemail.com
Tue Feb 2 11:21:26 CET 2016
Am 02.02.2016 08:34 schrieb "Anthony Walter" <sysrpl at gmail.com>:
>
> Sven,
>
> I missed this post when you made it a two days ago. If someone hasn't
already asked, does your implementation support short circuit evaluation?
>
> For example:
>
> BasketCount := IfThen(ShoppingList <> nil, ShoppingList.Count, 0);
>
> Where evaluating ShoppingList.Count will cause an exception if
ShoppingList is nil.
>
> Also the reverse should short circuit as well:
>
> BasketCount := IfThen(ShoppingList = nil, 0, ShoppingList.Count);
You're mixing up two things. Short circuit evaluation in terms of Pascal is
that in expressions using "and" and "or" the evaluation is aborted if the
result is already determined. This is controlled by a compiler directive
and is respected by all Boolean expressions.
What you mean is that the compiler does not evaluate all branches of the if
and that is the main reason I introduced this intrinsic. In fact the
IfThen() behaves just like an ordinary if-statement in that regard as I had
mentioned in my original mail.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160202/8c6d2843/attachment.html>
More information about the fpc-pascal
mailing list