make (a < b < c) illegal?

Lionello Lunesu lio at lunesu.remove.com
Wed Feb 7 23:16:27 PST 2007


Walter Bright wrote:
> Right now, in D (as well as C and C++), when you see the expression:
> 
>     if (a < b < c)
> 
> what is your first thought? Mine is that it was written by a newbie who 
> didn't realize that (a < b) returns true or false, and that it does NOT 
> mean ((a < b) && (b < c)). 

So your first thought, the newbie's first thought and my first thought 
all agree: it means a<b && b<c

As was pointed out already, let's make it that way. Adding these chained 
comparisons improves readability* and adds another popular feature from 
scripting languages.

L.

* compare with: if (a < b && c > b)



More information about the Digitalmars-d mailing list