[fpc-devel] new features and facilities
Mark Morgan Lloyd
markMLl.fpc-devel at telemetry.co.uk
Fri Oct 9 11:20:07 CEST 2015
Michael Van Canneyt wrote:
> On Fri, 9 Oct 2015, Sven Barth wrote:
>
>> Am 08.10.2015 23:48 schrieb "Michael Van Canneyt"
>> <michael at freepascal.org>:
>>> 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;
>>
>> That's probably only because other languages use that as the ternary.
>
> No, it is because there are no keywords involved.
>
> The keyword "If" starts a statement. It's a simple rule.
>
> As I said: by using "if" in an expression, you break the rule and
> introduce ambiguity.
>
>> There also another reason why I prefer the variant with the if: ease to
>> implement in the compiler.
>>
>> For the if one merely needs to add a corresponding case in factor() while
>> for the ?: one needs to fiddle with the compiler's operator precedence
>> rules that are applied in sub_expr() which can lead to desaster either
>> during implementation or later on when bugs are discovered...
>
> I don't see how the use of "if" differs from "?" in rules of precedence,
> they are at the exact same level.
> They're both just tokens to the compiler. At least "?" has the advantage
> of being new and not yet used, so is unambiguously.
Jonas, what's your take on this as an overall language guru?
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-devel
mailing list