make (a < b < c) illegal?

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Wed Feb 7 23:25:57 PST 2007


Lionello Lunesu wrote:
> 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)

I personally would like that. It is a good example of a dwim feature 
that doesn't add to the complexity of the language.

Andrei



More information about the Digitalmars-d mailing list