Allowing Expressions such as (low < value < high)

monarch_dodra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 4 13:25:50 PDT 2014


On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote:
> Are there any programming languages that extend the behaviour 
> of comparison operators to allow expressions such as
>
>     if (low < value < high)
>
> ?
>
> This syntax is currently disallowed by DMD.
>
> I'm aware of the risk of a programmer misinterpreting this as
>
>     if ((low < value) < high)
>
> Is this the reason why no languages (including D allows it).
>
> I'm asking for in some cases, where value is a long expression, 
> it would be a nice syntatic sugar to use.

In the case of D, it's a C compatibility thing. Other languages I 
don't know.


More information about the Digitalmars-d-learn mailing list