Allowing Expressions such as (low < value < high)

nikki via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Sep 7 13:21:57 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.

I know Coffeescript has them, they are called 'chained comparison 
operators' I believe and are a nice syntax cake imo. they are 
written as expected:
if 10 < a < 20


More information about the Digitalmars-d-learn mailing list