make (a < b < c) illegal?

Bill Baxter dnewsgroup at billbaxter.com
Wed Feb 14 10:41:08 PST 2007


Joel C. Salomon wrote:
> Russell Lewis wrote:
>>> The chain that I'm concerned about is this:
>>>     a==b == c==d
>>> which (the spacing makes clear) is meant to be
>>>     (a==b) == (c==d)
>>> but which could me misread as
>>>     (a==b) && (b==c) && (c==d)
>>> and which is probably (I'm not sure) currently implemented by the 
>>> compiler as:
>>>     ((a==b) ==c) ==d
>>>
>>> IMHO, C should have allowed comparison chaining from the start, but 
>>> since it didn't, I don't think that it would be a good idea to start 
>>> allowing it.  There will always be the newbies from C who will 
>>> misread it.  (sigh)
>>
>> Addendum: I would be ok with making the less than/greater than 
>> operators be chainable (since those operators are nonsense when used 
>> with boolean values), but I would ask that no expression be able to 
>> mix less-than and greater-than.  It would be ok to mix < with <=, but 
>> not < with >.
> 
> Why this prejudice?  With the chaining as people have discussed it,
>     a < b > c
> expands to
>     (a < b) && (b > c)
> — why would you prohibit this?

I would assume the reason is because it's not used in math.

--bb



More information about the Digitalmars-d mailing list