syntax idea: simplifed ifs

Hasan Aljudy hasan.aljudy at gmail.com
Mon Apr 10 17:03:57 PDT 2006


dennis luehring wrote:
> for example how often do we use constructs like
> 
> if( x ==  10 && x == 20 && x == 30 )
> 
> simplified:
> if( x == [10 && 20 && 30] )
> 
> if( a >= h && b >= h && c >= h )
> 
> simplified:
> if( [a && b && c] >= h )
> 
> (just an idea)
> 
> ciao dennis

I've always wanted something like this!!!! but I think the proposed 
syntax might not fit very well with the D grammar.

hmm, come to think of it, maybe it can already be implemented with 
templates.

so,

if( x == 10 || x == 20 || x == 30 )

becomes:
if( equals!(x).anyOf( 10, 20, 30 ) )

or something like that!

any template guru up to it?

On a side note: the expression( x == 10 && x == 20 && x == 30 ) is 
rediclious, it's always false ;)



More information about the Digitalmars-d mailing list