[fpc-devel] new features and facilities
Michael Van Canneyt
michael at freepascal.org
Thu Oct 8 23:49:21 CEST 2015
On Thu, 8 Oct 2015, Sven Barth wrote:
> Am 08.10.2015 19:10 schrieb "Ralf Quint" <freedos.la at gmail.com>:
>>
>> On 10/8/2015 9:54 AM, Sven Barth wrote:
>>>
>>>
>>> I had the idea to implement inline-if as well. I think the syntax I
> selected is derived from Oxygene, but it looks very Pascal and shouldn't
> break anything:
>>>
>>> left := if expr1 then expr2 else expr3;
>>>
>>> Thereby expr1 returns Boolean and expr2 determines the type of the whole
> inline-if, thus expr3 needs to be compatible to expr2.
>>>
>>>
>> Sorry, but that doesn't "look Pascal" at all, and is anything but easily
> understandable, specially given the possible complexity of expr[1,2,3]...
>
> And you think C's ternary would be more Pascal? Also you need /some/
> definition of what defines the type no whether what syntax you choose (in
> addition expr1 is the same as in normal ifs, so it's only the "complexity"
> of expr2 and expr3). And no, "the left side" is not the Pascal answer
> either.
Actually, yes I think C's or Javascript's ternary is better suited.
Let me explain. If I see
If expr1 then expr2 else expr3
it says 'statement' to me. But
a ? b : c;
Says "expression" to me.
So
left := a ? b : c;
looks more 'right' than the 'if then else', because the right-hand side is clearly an expression.
The "if expr1 then expr2 else expr3" is equally counter-intuitive and confusing as anonymous functions.
Keyword "If" starts a statement. If you allow to use it in expressions, its meaning becomes context sensitive.
That is a bad thing in my book.
So if this thing needs to be implemented, then I'd much prefer it in the ternary form.
Michael.
More information about the fpc-devel
mailing list