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

Sven Barth pascaldragon at googlemail.com
Tue Feb 2 11:32:17 CET 2016


Am 02.02.2016 10:41 schrieb "Serguei TARASSOV" <serge at arbinada.com>:
>
> On 02/02/2016 10:29, fpc-pascal-request at lists.freepascal.org wrote:
>>
>> 2016-02-01 10:59 GMT+01:00 Michael Schnell<mschnell at lumino.de>:
>> Same here. I see no reason to differ from it. Introducing new
>> incompatibility is bad idea. For me is good to have booth (Oxygene
>> compatible):
>>
>> x := iif (a < 3, 1, 2);
>> V := If a < 3 then 1 else 2;
>>
>> sometimes is better to use first option and sometimes is better to use
>> second option. Both Oxygen compatible and very "pascalish".
>
> No, the second is always better because safer.
>
> x := iif (Obj = nil, 0, Obj.Value);
> This will raise access violation as a normal function or you depend on
compiler implementation for this special case. And you should remember an
additional special case of function.

That's why the current IfThen() is an intrinsic, to allow this.

> x := iif Obj = nil then 0 else Obj.Value;
> Doesn't raise AV because it's a statement, not function.

It's not a statement, it's an expression. Also I won't introduce a new
keyword ("iif") just for this.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160202/29f2470c/attachment.html>


More information about the fpc-pascal mailing list