make (a < b < c) illegal?

Russell Lewis webmaster at villagersonline.com
Tue Feb 13 10:47:50 PST 2007


Derek Parnell wrote:
> On Wed, 07 Feb 2007 17:09:35 -0800, Andrei Alexandrescu (See Website For

>> What's the intended meaning of:
>>
>> a < b == c < d
> 
> Well that *obvious*!
> 
>  (((a < b) && (b == c)) < d)  <G>
> 
> Okay, okay, I see your point. But it would be useful (one day) to easily
> code the idiom  (a op b) && (b op c),  no? 
> 
> How about someone knocking up a mixin template for expressions of this
> format? I haven't got a clue how it could be done as the
> mixin/template/meta-programming syntax and semantics of D is still so
> obtuse and confusing to me that I can only do the very simplest things and
> then only after many false starts.

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)



More information about the Digitalmars-d mailing list